开发者

Selecting XML node together will all children

开发者 https://www.devze.com 2023-01-29 18:18 出处:网络
I want to select a node together with all child nodes from an XML document that I have loaded. What method whould I use to get, for example below, <item2> and all开发者_开发技巧 child nodes (chi

I want to select a node together with all child nodes from an XML document that I have loaded. What method whould I use to get, for example below, <item2> and all开发者_开发技巧 child nodes (child 2.1,2.2,2.3)?

<xmldoc>
  <item1>
    <child1.1>
    <child1.2>
    <child1.3>
  </item1>
  <item2>
    <child2.1>
    <child2.2>
    <child2.3>
  </item2>
</xmldoc>


Assuming you need (as mentioned in question) to select item2 and all its child nodes, XPath expression will be

xmldoc/item2 | xmldoc/item2/*

And if you need all descendants (e.g. for more complicated structure)

xmldoc/item2/descendant-or-self::*


The xpath expression should be /xmldoc/item2/* Otherwise you should specify in what language...

0

精彩评论

暂无评论...
验证码 换一张
取 消