我正在尝试从根目录中选择第二个子节点以及所有来自XML的子节点,它看起来与此类似:
<root>
<SET>
<element>
<element>
</SET>
<SET>
<element>
<element>
</SET>
<root>
Run Code Online (Sandbox Code Playgroud)
我是第二个节点中的所有标签,任何帮助将不胜感激!
我正在使用C#.我尝试了XPath/SET [1]但是没有看到帮助!
非常感谢!
C
x/y[1] :
The first <y> child of each <x>. This is equivalent to the expression in the next row.
x/y[position() = 1] :The first <y> child of each <x>.
Run Code Online (Sandbox Code Playgroud)
试试这个 :
string xpath = "/root/set[2]";
XmlNode locationNode = doc.SelectSingleNode(xpath);
Run Code Online (Sandbox Code Playgroud)
要么
string xpath = "/root/set[position() = 2]";
XmlNode locationNode = doc.SelectSingleNode(xpath);
Run Code Online (Sandbox Code Playgroud)