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

后端 未结 2 610
不知归路
不知归路 2020-12-04 19:09

I need an XPath to fetch all ChildNodes ( including Text Element, Comment Element & Child Elements ) without Parent Element. Any help

Sample Example:

<         


        
2条回答
  •  心在旅途
    2020-12-04 19:41

    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()
    

提交回复
热议问题