1 / 12

XQuery

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

mura
Download Presentation

XQuery

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XQuery Leah Andrews

  2. Overview • Queries data stored in XML trees • Declarative • High-level • Functional (no side effects) • Strongly typed • Nodes • Atomic values (integers, strings, booleans)

  3. 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

  4. XQuery v. XSLT • Overlapping capabilities • Share a data model, type system, function library and XPath

  5. XQuery > XSLT • Better usability • More concise • Other languages can be embedded • More Orthogonal • Can be expressed in XML syntax (XQueryX)

  6. XSLT > XQuery • Better for small-scale changes to XML documents • Widespread use • More flexible for transformations

  7. XQuery does NOT support: • Full text search capacity • Updating XML documents or databases • Dynamic typing • Polymorphism

  8. FLWOR • FOR • LET • WHERE • ORDER BY • RETURN

  9. <?xml version="1.0" encoding="ISO-8859-1"?> <class> <students> <student name="Leah"> <studentId>1</studentId> <laptop>MacBook</laptop> <favoritecolor>olive</favoritecolor> </student> <student name="Ian"> <studentId>2</studentId> <laptop>WinBook</laptop> <favoritecolor>orange</favoritecolor> </student> <student name="Kyle"> <studentId>3</studentId> <laptop>Toshiba</laptop> <favoritecolor>orange</favoritecolor> </student> <student name="Chris"> <studentId>4</studentId> <laptop>Gateway</laptop> <favoritecolor>green</favoritecolor> </student> <student name="Stacy"> <studentId>5</studentId> <laptop>Asus</laptop> <favoritecolor>rainbow</favoritecolor> </student> <student name="Tom"> <studentId>6</studentId> <laptop>ZT</laptop> <favoritecolor>black</favoritecolor> </student> <student name="Brad"> <studentId>7</studentId> <laptop>IMB</laptop> <favoritecolor>unknown</favoritecolor> </student> </students> <professors> <professor name="Axel"> <id>8</id> <laptop>MacBook</laptop> <favoritecolor>German</favoritecolor> </professor> </professors> </class>

  10. xquery version "1.0"; <html> <body> <p>All students</p> <ul> { for $x in doc("students.xml")/class/students order by $x/studentId return <li> { $x } </li> } </ul> </body> </html>

  11. xquery version "1.0"; <html> <body> <p>Students with an id less than 5</p> <ul> { for $x in doc("students.xml")/class/students where $x/studentId<5 order by $x/studentId return <li> {data($x/@name)} </li> } </ul> </body> </html>

  12. xquery version "1.0"; <html> <body> <p>Favorite (student) colors</p> <ul> { for $x in doc("students.xml")/class/students/favoritecolor return <li> {data($x)} </li> } </ul> </body> </html>

More Related