Andy Reitz (blog)

 

 

JavaOne: TS-5163: XQuery for the Java Technology Geek

What is XQuery?
  • New language from W3C
  • Queries XML (documents, rdbms, etc.)
  • Anything with some structure
  • under development, not 1.0, at candidate recommendation stage
XQuery advantages over:
  • XSLT - easier to read and write, maintain; designed with DB optimization in mind
  • SQL - better for hierarchical data (things that don't fit: book data, medical records, yellow pages). DB is designed for columns of numbers.
  • Procedural - define what you want, let engines optimize
demo
  • When pulling data out of XML, easier to show more context around the data
  • Like breadcrumbs to book, chapter, section
  • Then show not only the search term, but also the content around it
Loading Content
  • depends on engine, indexed stores require pre-loading
Vendors
  • Mark Logic (presenters, demos available), eXist (OSS), Saxon
  • Coolest hidden XQuery implementation: Apple's Sherlock
XQuery uses XPath
  • a matching language to select portions of an XML document
  • Like RE engine for XML; "give me every one of these where that or this"
FLWOR expressions
  • pronounced "flower"
  • stand for: for, let, where, order by, return
  • this is one expression, not five
  • XQuery is technology to manipulate XML that you can find with XPath
  • XQuery doesn't have to produce XML output -- can produce sequence of elements, or just plain text
Deployment: CGI-style
  • Works well on web tier
  • Executes in response to HTTP requests like CGI
  • Speaks XML to back-end, XHTML to front end
  • advantage is easy-and fast, can do blog or searchable FAQ as XQuery (backend is XML, XQuery formats and displays on frontend)
Deployment: Direct Style (POJO)
  • Call XQuery stack from Java language
  • Think JDBC but for XQuery
  • Fits in your Java technology stack
Deployment: JSP Style
  • XQuery JSP tag library
  • send results straight out, or store in variables
In summary, I feel like I finally understand what XQuery and XPath are all about. This presentation gave a fantastic overview of both, in a way that was engaging and made the two complimentary technologies easy to understand. I don't know if these two technologies are directly relevant to my current work at EDS, but who knows what the future may bring. If you are working with structured data in XML, you need to check out XQuery and XPath.