XQuery: 1 W3C (World Wide Web Consortium) What is W3C? –An industry consortium, best known for standardizing HTML and XML. –Working Groups create or adopt new “recommendations”
XQuery: 2 XML (eXtensible Markup Language) TCP/IP Illustrated Stevens W. Addison Wesley …
XQuery: 3 XQuery – Example 1 Get title of books published by Addison-Wesley after for $b in $bib/book where $b/publisher = "Addison-Wesley" and > 1993 return $b/title TCP/IP Illustrated
XQuery: 4 FLWOR Expressions Basic FLWOR Expression: –For – consider (introduce a variable) –Let – introduce additional variables –Where – filter by conditions –Order by – order the output –Return – build results Xquery is compositional: any place XML data can go, another { FLWOR } expression can go.
XQuery: 5 XQuery – Example 2 Get titles of books published after 1994, but NOT published by Addison-Wesley. Order the result in descending order by title. for $b in $bib/book let $c := $b/publisher where $c != "Addison-Wesley" and > 1994 order by $b/title descending return $b/title The Economics of Technology and Content for Digital TV Early Adopter XQuery Data on the Web
XQuery: 6 XQuery – Example 3 Join and on and print the title and price. for $b in $bib/book, $e in $reviews/entry where $e/title = $b/title return { $b/title, $e/price } TCP/IP Illustrated Advanced Programming in the Unix environment Data on the Web 34.95
XQuery: 7 XQuery – Example 4 Get the average price of the books. { let $prices := $bib/book/price return { avg($prices) } } Should be: Actually is: type error: no common aggregate type because price is declared to be of type string
XQuery: 8 XQuery – Example 4 (continued) Get the average of the years of the books. { let $years := return { avg($years) } }
XQuery: 9 XQuery – Example 5 Get year (as an attribute) and title of book. (Use a predicate to limit the books to those published by Addison-Wesley.) for $b in $bib/book, $c in $b[publisher = "Addison-Wesley"] return { } { $c/title } TCP/IP Illustrated Advanced Programming in the Unix environment