Download presentation
Presentation is loading. Please wait.
Published byBarbara Hunter Modified over 9 years ago
1
XQuery John Annechino Steven Pow
2
Agenda What is XQuery? Uses of XQuery XQuery vs. XSLT Syntax –Built-In Functions –FLWOR –if-then-else –User-Defined Functions Examples Future of XQuery References
3
What is XQuery? The best way to explain XQuery is to say that XQuery is to XML what SQL is to database tables. It is the language for querying XML data. XQuery is a language for finding and extracting elements and attributes from XML documents. XQuery is designed to query XML data – not just XML files, but anything that can appear as XML.
4
Uses of XQuery Extract information to use in a Web Service Query XML documents Read data from databases and generate reports Transform XML data Search Web documents for relevant information
5
XQuery vs. XSLT XSLT has a “processing engine” that automatically goes through the document tree and applies templates as it finds nodes With XQuery, the the programmer is responsible for directing the process.
6
Syntax Elements, attributes, and variables must be valid XML names XQuery is built up with XPath expressions XML Schema datatypes are used XQuery variable is defined with a $ followed by a name Comments are delimited by (: and :) (: this is a comment :)
7
books.xml Learning XML Erik T. Ray 2003 39.95 Harry Potter J K. Rowling 2005 29.99
8
Built-In Functions doc(‘books.xml’)/bookstore/book[price>30] Learning XML Erik T. Ray 2003 39.95 XQuery includes over 100 built-in functions
9
FLWOR For – binds a variable to each item returned by the in expression Let – allows variable assignments Where – used to specify criteria for result Order by – defines the sort-order Return – specifies what is to be returned
10
FLWOR doc(‘books.xml’)/bookstore/book[price>30]/title Learning XML for $x in doc(‘books.xml’)/store/book where $x/price>30 return $x/title Learning XML
11
FLWOR { for $x in doc(“books.xml”)/bookstore/book order by $x/title return {data($x/title)} } Harry Potter Learning XML
12
if-then-else for $x in doc("books.xml")/bookstore/book return if ($x/@category="CHILDREN") then {data($x/title)} else {data($x/title)} Learning XML Harry Potter
13
User-Defined Functions declare function prefix:function_name($parameter AS datatype) AS returnDatatype { (:...function code here... :) }; XQuery shares the same datatypes as XML Schema, including Date, String, Numeric, and other Misc types
14
User-Defined Functions declare function local:minPrice( $price as xs:decimal, $discount as xs:decimal) AS xs:decimal { let $disc := ($price * $discount) div 100 return ($price - $disc) }; { local:minPrice($book/price, $book/discount) }
15
XQuery Examples
16
Future of XQuery XQuery is currently a Working Draft XQuery is compatible with several W3C standards, such as XML, Namespaces, XSLT, XPath, and XML Schema XQuery 1.0 is not yet a W3C Recommendation. Hopefully it will be a recommendation in the near future.
17
References http://www.w3c.org/XML/Query.html http://www.w3schools.com/xquery/default.asp http://www.w3schools.com/xpath/xpath_functions.asp http://www.xmlmind.com/qizxopen.html XQuery: The XML Query Language, by Michael Brundage
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.