May 28, 2021 XQuery
In the last section, we covered the syntax rules for XQuery.
In this section, let's study some basic XQuery syntax by looking at an example.
We'll use this XML document in the following example.
"books.xml":
View the "books" file .xml your browser.
XQuery uses functions to extract data from XML documents.
doc() to open the "books.xml" file:
XQuery uses path expressions to navigate through elements in an XML document.
The following path expression is used to pick .xml title elements in the "books" file:
(/bookstore picks the bookstore element, /book picks all the book elements under the bookstore element, /title picks all the title elements under each book element)
XQuery above extracts the following data:
XQuery uses predicates to qualify the data extracted from the XML document.
The following predicate is used to select all book elements under the bookstore element, and the value of the price element under the selected book element must be less than 30:
The XQuery above extracts the following data:
That's what you learned about the XQuery basic syntax, and in the next section, you'll learn that if you use FLWOR to pick nodes from the "books.xml" section.