How to get all elements from XML via XQuery

I need to get all XML elements present in a given file via XQuery. For example,

<xml>
   <a>attr="one"
       <b>attr2="in-a"
           <c>leaf</c>
       </b>
   </a>
</xml>

      

the output should return the following:

<xml>,<a>,<b>,<c> 

      

and, if possible, hierarchically. And I only need to use XQuery.

Any help is appreciated. Thank.

+3


source to share


1 answer


This should work where the /test.xml

document contains:



fn:string-join(fn:doc('/test.xml')//*/(concat(name(.), ' > ')))

      

+4


source







All Articles