我有一个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...
}
}
我收到以下消息:
根目录内容的内容子项1的内容
子项1的内容
但我需要如下的消息:
根目录的内容
子项1的内容
如何解决?