XQuery uses functions to extract the data from XML documents.
The doc() function is basically used to open the "bookdetails.xml" file:
doc("bookdetails.xml")
Path Expressions
XQuery uses path expressions to navigate through elements in the XML document.
The following path expression is used to select all the title element in the "bookdetails.xml" file:
doc("bookdetails.xml")/bookstore/book/title
(/bookstore selects the bookstore element, /book selects all
the book elements under the bookstore element, and /title
selects all the title element under each book element)
The
XQuery above will extract the following result:
XQuery uses predicates to limit the extracted data from the XML
documents.
The following predicate is used as to select all the
book elements under the bookstore element that have a price
element with a value that is less than 30:
doc("bookdetails.xml")/bookstore/book[price<30]
The XQuery above will extract the following result: