Hardik
Hardik

Reputation: 57

How to get all elements from XML through XQuery

I need to get all XML elements present in a given file through XQuery. For eg:

<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 in hierarchical manner. And I need to use only XQuery.

Any help appreciated.Thanks.

Upvotes: 3

Views: 900

Answers (1)

Tamas
Tamas

Reputation: 11244

This should work, where /test.xml contains the document:

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

Upvotes: 4

Related Questions