XDocument parsing value
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 dat开发者_StackOverflowa?
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);
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.
精彩评论