[英]XPath : Get nodes where child node contains an attributeHow to select node that have and attribute and whose parent have another attribute in c#
我有一个像XML
<Validation>
<Presentation>
<Slide Tag = "Pippo">
<Shape Name = "Pluto"/>
</Slide>
<Shape Name = "Pluto"/>
</Presentation>
</Validation>
我如何改善此C#代码段
String xPath = string.Format("/Validation/Presentation/Shape[@Name='{0}'][1]", "Pluto");
XmlNode node = doc.DocumentElement.SelectSingleNode(xPath);
仅获得属性名称为“ Pluto”且其父级具有标签为“ Pippo”的形状节点?
您可以使用以下Xpath字符串获取此节点:
string xPath = string.Format("//*[@Tag='{0}']/Shape[@Name='{1}']", "Pippo","Pluto");
XmlNode node = doc.DocumentElement.SelectSingleNode(xPath);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.