XQuery speeds up the process of finding information contained in an XML document -- which is very handy when dealing with long XML documents. This article, the second of two parts, will teach you how to write XQuery expressions. It is excerpted from chapter nine of the book XML DeMYSTiFieD, written by Jim Keogh and Ken Davidson (McGraw-Hill/Osborne, 2005; ISBN: 0072262109).
XQuery is used to query information contained in an XML document. The XQuery is processed by the XQuery processor. Some of these processors are freeware or open source and others are commercial software products.
An XQuery is typed into an editor and saved to a file that contains the .xq file extension. The XQuery file is then passed to the XQuery processor as a command line argument. The result of the XQuery is contained in the output.html file, which you can open in your browser.
An XQuery contains conditional expressions that define search criteria. A conditional expression can be either true or false. Portions of the XML document that meet the search criteria are copied to the output.html file.
The for and let clauses are used to assign values to variables within the XQuery. The order by clause is used to sort the results in ascending or descending order. The where clause specifies a filter criteria using the conditional expression and the return clause identifies information that the XQuery processor returns to the output .html file.
Saxon-B is the only software that can process an XQuery.
What kind of clause is used to specify the filter criteria?
a. SQL clause
b. Declarative clause
c. where clause
d. None of the above
$x is an
a. Places all elements in the XML document in ascending order
b. Places all elements in the XML document in descending order
c. Places all return values in ascending order by default
d. Places all return values in descending order by default
The where clause
a. Locates the XML document
b. Locates the output file
c. Specifies the filter criteria
d. All of the above
All functions used by an XQuery are built-in functions.
The data() function returns the text value of a variable.
a. Converts information contained in an XML document to another data type
b. Is the first instance of a function
c. Is the first instance of a variable
d. None of the above
The doc() function retrieves an XML document.
The round-half-to-even() function rounds half the value returned by a function.
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.