XQuery Leah Andrews
Overview Queries data stored in XML trees Declarative High-level Functional (no side effects) Strongly typed Nodes Atomic values (integers, strings, booleans)
Origins Became a W3 standard in January, 2007 Developed by Jonathan Robie, Don Chamberlin and Daniela Florescu Compatible with other W3 standards XML (namespaces, Schema), XSLT, XPath
XQuery v. XSLT Overlapping capabilities Share a data model, type system, function library and XPath
XQuery > XSLT Better usability More concise Other languages can be embedded More Orthogonal Can be expressed in XML syntax (XQueryX)
XSLT > XQuery Better for small-scale changes to XML documents Widespread use More flexible for transformations
XQuery does NOT support: Full text search capacity Updating XML documents or databases Dynamic typing Polymorphism
FLWOR FOR LET WHERE ORDER BY RETURN
1 MacBook olive 2 WinBook orange 3 Toshiba orange 4 Gateway green 5 Asus rainbow 6 ZT black 7 IMB unknown 8 MacBook German
xquery version "1.0"; All students { for $x in doc("students.xml")/class/students order by $x/studentId return { $x } }
xquery version "1.0"; Students with an id less than 5 { for $x in doc("students.xml")/class/students where $x/studentId<5 order by $x/studentId return }
xquery version "1.0"; Favorite (student) colors { for $x in doc("students.xml")/class/students/favoritecolor return {data($x)} }