views:

250

answers:

1

In the code snippet below, I only have 1 element in the XML that has text data:

<element>like this</element>

All the other elements have attributes or nothing.

Why would my parsing below seem to indicate that ALL of my elements have "like this" as text data?

thx

StreamWriter sw = new StreamWriter(out_file_name_);

var xd = XDocument.Load(xml_template_file_name_);

foreach (XElement el in xd.Descendants()) 
     sw.Write(el.Name + "-" + el.Value);
A: 

I think the answer is nesting, if your XML looks like this:

<root>
  <group1>
  <element>text</element>
  </group1>
  <group2></group2>
</root>

Then all elements except group2 will have 'text' as value.

Henk Holterman
wow. Then XDocument is just a big fat liar ;( I'll check out nesting - thanks.
Chris
You can use a check on `!el.hasElements`
Henk Holterman