【发布时间】:2017-02-09 15:11:00
【问题描述】:
我有 xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<root lev="0">
content of root
<child1 lev="1" xmlns="root">
content of child1
</child1>
</root>
和下一个代码:
XDocument xml = XDocument.Load("D:\\test.xml");
foreach (var node in xml.Descendants())
{
if (node is XElement)
{
MessageBox.Show(node.Value);
//some code...
}
}
我收到消息:
child1的rootcontent的内容
child1 的内容
但我需要消息:
根目录
child1 的内容
如何解决?
【问题讨论】:
标签: c# xml linq-to-xml