我有像
这样的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”的形状节点,其父级具有属性Tag“Pippo”?
答案 0 :(得分:4)
您可以使用以下Xpath字符串获取此节点:
string xPath = string.Format("//*[@Tag='{0}']/Shape[@Name='{1}']", "Pippo","Pluto");
XmlNode node = doc.DocumentElement.SelectSingleNode(xPath);