gpt4 book ai didi

c# - XPath : Get nodes where child node contains an attributeHow to select node that have and attribute and whose parent have another attribute in c#

转载 作者:太空宇宙 更新时间:2023-11-03 21:21:11 27 4
gpt4 key购买 nike

我有一个类似的 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);

关于c# - XPath : Get nodes where child node contains an attributeHow to select node that have and attribute and whose parent have another attribute in c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30577799/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com