-3

I know how to read normal xml files with c# using XmlDocument. But this time the xml file is different, this is the structure:

<year>2010</year>
  <value>20000</value>
  <exp>k(x + y)/m</exp>
  <item>30</item>
    <law>Ley 10, art. 40</law>
    <law>Ley 10, art. 50</law>
  <item>140</item>
    <law>Ley 10, art. 40</law>
  <year>2011</year>

As you can see, year is the parent node of value, exp and item and item is the parent of law childs. So this is not like the normal

<parent> <child>a</child> </parent>

xml file structure. Can you please give me a hint. Thanks.

user3776792
  • 41
  • 1
  • 2
  • 6
    Your indentation is highly misleading - you've *just* got a sequence of elements there. None of them contain anything other elements. – Jon Skeet Jan 22 '15 at 16:17
  • 1
    You can't just slap a couple of angle brackets together and call it XML. This isn't XML, and you can't parse it as such. Whitespace doesn't matter in XML. If this really is all data you have to work with, you'll have to create your own parser. – CodeCaster Jan 22 '15 at 16:20
  • 2
    Are you saying that the indentation level dictates the hierarchy of these "XML" nodes? If so, shouldn't the last `` line be at the same level as the first one? – Cᴏʀʏ Jan 22 '15 at 16:24

1 Answers1

1

In your example, year is not the parent of value, exp, and item as you state; it's a sibling node. This structure is not well-formed XML because there are multiple root nodes, which is not permitted. To get it to parse, you'll need to wrap it in an outer set of tags.

adv12
  • 8,443
  • 2
  • 24
  • 48