0

I am trying to parse a XML-file, that could have different element names, except the root.

I would like to get first a list of all "Stockholm", "London".. etc (names would be unknown to the application). Then i would like to get all sub-elements of each "Stockholm". I am trying to build a treeview with this information, where the parts "Stockholm" and "London" would be the root of each node, and the child elements with id/name/tag should get listed under each previous element.

An example how the XML-file would look like is this

<?xml version="1.0" encoding="utf-8"?>

<Nodes>
  <Stockholm>
    <id>101</id>
    <Name>Södertälje</Name>
    <Tag>digital2</Tag>
  </Stockholm>
  <Stockholm>
    <id>102</id>
    <Name>Kungens Kurva</Name>
    <Tag>digtal1</Tag>
  </Stockholm>
  <London>
    <id>201</id>
    <Name>Bloomsbury</Name>
    <Tag>digital2</Tag>
  </London>
  <London>
    <id>202</id>
    <Name>Brixton</Name>
    <Tag>digtal1</Tag>
  </London>
  <Tokyo>
    <id>301</id>
    <Name>Ogasawara Island</Name>
    <Tag>digtal1</Tag>
  </Tokyo>
  <Tokyo>
    <id>302</id>
    <Name>Izu</Name>
    <Tag>digital2</Tag>
  </Tokyo>
  <Washington>
    <id>401</id>
    <Name>Pleasant Plaint</Name>
    <Tag>digital2</Tag>
  </Washington>
  <Washington>
    <id>402</id>
    <Name>Georgetown</Name>
    <Tag>digtal1</Tag>
  </Washington>
</Nodes>

How would i go about to do this in silverlight? All example code i have found, assumes one knows all elements by name.

  • Where is the XML coming from, you might have to re think the format. The city name really needs be an attribute of a node, for instance.... 101..... This would then make it very easy to de-serialize – Monty Apr 29 '16 at 11:17
  • See recursive method on following webpage. Have recommended this solution a lot. http://stackoverflow.com/questions/28976601/recursion-parsing-xml-file-with-attributes-into-treeview-c-sharp – jdweng Apr 29 '16 at 12:13
  • I re-made the file into a CSV-file instead, much easier to handle the information this way it seems. (When the document is dynamically created). – Stefan Grönberg May 02 '16 at 06:42

0 Answers0