Blog
DB2utor

Categories

July 17, 2012

Learning XQUERY

Over the years I’ve written often about the significance of XML. As XML becomes more commonly used in mainframe environments, IBM continues to expand the capability of DB2 for z/OS to manage XML documents: first with XPATH and then with XQUERY.

To understand when to use XPATH and when to use XQUERY, I recommend the DB2 for z/OS PureXML Guide. But basically, XPATH should be used when you need to identify qualifying documents in an XML column using XMLEXISTS function. This is because XPATH is more efficient than XQUERY; it can take advantage of XML indexes with the XMLEXISTS predicate.

XQUERY, on the other hand, should be utilized when you need to use constructors or conditional logic. You cannot use an XML index with XQUERY expressions.

XQUERY was introduced in DB2 10 for z/OS in November 2011 through APARs PM47617 and PM47618. (It was unveiled on DB2 for LUW about five years earlier.) The IBM Redbook, "XQuery in IBM DB2 10 for z/OS," explains the basics of XQuery through simple examples.

In addition, this publication reviews the basic constructs of the XQUERY language and explains the three types of XQuery expressions. Coding are examples provided for:

  • FLWOR
  • direct XML constructors
  • conditional expressions

 For more in-depth information, you should also read the Redbook, "Extremely pureXML in DB2 10 for z/OS." Other reference materials, including technical articles, webcasts, podcasts/presentations, demos and sample downloads are available from the IBM developerWorks DB2 for z/OS pureXML home page.

I'm seeing more mainframe organizations develop in XML and store and manage XML documents in DB2 for z/OS. If your company uses XML, please share some of your experiences in Comments.