XML/XQuery/node
Query from root element
File: Data.xml
<?xml version="1.0"?>
<Books>
<Book>A</Book>
<Book>B</Book>
<Book>C</Book>
</Books>
File: Query.xquery
doc("Data.xml")/Books/Book
Output:
<?xml version="1.0" encoding="UTF-8"?>
<Book>A</Book>
<Book>B</Book>
<Book>C</Book>
Select element by level
File: Data.xml
<?xml version="1.0"?>
<bib>
<book year="1988">
<title>title 1</title>
</book>
<book year="2004">
<title>title 2</title>
</book>
</bib>
File: Query.xquery
<myNewBib>{
doc("Data.xml")/bib/book
}</myNewBib>
Output:
<?xml version="1.0" encoding="UTF-8"?>
<myNewBib>
<book year="1988">
<title>title 1</title>
</book>
<book year="2004">
<title>title 2</title>
</book>
</myNewBib>
XQuery and element
File: Data.xml
<?xml version="1.0"?>
<Books>
<Book>A</Book>
<Book>B</Book>
<Book>C</Book>
</Books>
File: Query.xquery
<Books>
{doc("Data.xml")/Books/Book}
</Books>
Output:
<?xml version="1.0" encoding="UTF-8"?>
<Books>
<Book>A</Book>
<Book>B</Book>
<Book>C</Book>
</Books>