开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜