Introduction to XQuery

Source: Internet
Author: User
In this section, let's study an example to learn some basic XQuery syntax. We will apply this XML document in the following example. Reference content: books. xml :? Xmlversion = 1.0 encoding = ISO-8859-1? B

In this section, let's study an example to learn some basic XQuery syntax.

XML instance document

We will apply this XML document in the following example.

Reference content is as follows:
"Books. xml ":



Everyday Italian
Giada De Laurentiis
2005
30.00


Harry Potter
J k. Rowling
2005
29.99


XQuery Kick Start
James McGovern
Per Bothner
Kurt Cagle
James Linn
Vaidyan#nagarajan
2003
49.99


Learning XML
Erik T. Ray
2003
39.95

How to select a node from "books. xml?

Function

The XQuery application function is used to extract data from XML documents.

Doc () is used to open the "books. xml" file:

Doc ("books. xml ")

Path expression

The XQuery application path expression is used to navigate through elements in the XML document.

The following path expression is used to select all the title elements in the "books. xml" file:

Doc ("books. 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 elements under each book element)

The preceding XQuery can extract the following data:

Reference content is as follows:
Everyday Italian
Harry Potter
XQuery Kick Start
Learning XML

Predicates

XQuery uses predicates to limit the data extracted from XML documents.

The following predicates are used to select all the book elements under the bookstore element, and the value of the price element under the selected book element must be less than 30:

Doc ("books. xml")/bookstore/book [price <30]

The preceding XQuery can extract the following data:

Reference content is as follows:


Harry Potter
J k. Rowling
2005
29.99



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.