xpath获取全部的child nodes without parent


Xml – XPath to get all child nodes (elements, comments, and text) without parent



Best Solution

From the documentation of XPath ( http://www.w3.org/TR/xpath/#location-paths ):

child::* selects all element children of the context node 

child::text() selects all text node children of the context node 

child::node() selects all the children of the context node, whatever their node type

So I guess your answer is:

$doc/PRESENTEDIN/X/child::node()

And if you want a flatten array of all nested nodes:

$doc/PRESENTEDIN/X/descendant::node()


https://itecnote.com/tecnote/xml-xpath-to-get-all-child-nodes-elements-comments-and-text-without-parent/
阅读量: 368
发布于:
修改于: