如下xml文档
<?xml version="1.0" encoding="UTF-8"?>
<root>
<tree name="top"><leafage></leafage></tree>
<tree name="middle"><leafage></leafage></tree>
<tree name="bottom"><leafage></leafage></tree>
<tree name="top"><leafage></leafage></tree>
<tree name="middle"><leafage></leafage></tree>
<tree name="bottom"><leafage></leafage></tree>
</root>
怎么用xpath查出所有的tree name
结果应为 top,middle,bottom
<?xml version="1.0" encoding="UTF-8"?>
<root>
<tree name="top"><leafage></leafage></tree>
<tree name="middle"><leafage></leafage></tree>
<tree name="bottom"><leafage></leafage></tree>
<tree name="top"><leafage></leafage></tree>
<tree name="middle"><leafage></leafage></tree>
<tree name="bottom"><leafage></leafage></tree>
</root>
怎么用xpath查出所有的tree name
结果应为 top,middle,bottom
解决方案 »
- Arraylist datatable数据量限制
- des解密后结果变得不一样了
- 请教关于DCM显示的解决方案
- 问题还是没解决,谁帮帮我?
- ----高分求!! 关于COM 对象无效或未注册的问题~~~~~~~~~~
- 急 c# 使用twian做扫描仪参数设置
- 怎么判断十六进制数据,并将其转换成10进制数据
- 各位大哥:怎样用C#做个程序将word的窗口设置成总在最前显示?
- TreeView控件编程遇到的重大难题?
- 如何通过DHTMLEDIT控件来操做编辑页面?
- C#如何获取QQ安装路径 ?并且让其获取textbox的值进行登陆?
- C# FileSystemWatcher 如何监控Changed到底是哪种更改引起的?
xd.Load(@"..\..\XMLFile1.xml");
XmlNodeList node = xd.SelectNodes("root/tree");
foreach (XmlNode cnode in node)
Console.WriteLine(cnode.Attributes["name"].Value);
XmlNodeList node = xd.SelectNodes("root/tree/@name");
foreach (XmlNode cnode in node)
Console.WriteLine(cnode.Value);这样也可以
<root>
<tree name=""top""> <leafage> </leafage> </tree>
<tree name=""middle""> <leafage> </leafage> </tree>
<tree name=""bottom""> <leafage> </leafage> </tree>
<tree name=""top""> <leafage> </leafage> </tree>
<tree name=""middle""> <leafage> </leafage> </tree>
<tree name=""bottom""> <leafage> </leafage> </tree>
</root>
";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(str);
//*[not( name()=name(following-sibling::*) )]
XmlNodeList nodes = xmlDoc.SelectNodes("root/tree[not(@name=following-sibling::tree/@name)]/@name");
foreach (XmlNode node in nodes)
{
Console.WriteLine(node.Value);
}输出:top,middle,bottom
following_sibling与preceding-sibling都可以;