DB2 & IMS

 

If you look closely at the two “Department” documents generated, you can see the formation of a nice hierarchical structure that contains the relevant department and employee information. All this was generated from traditional DB2 relational table structures!

DB2 also provides for a simple way to move XML data that has been stored in string columns into columns with an XML data type. The XMLPARSE function can take a string representation of a well-formed XML document and convert it into an XML value. This can make the transition from storing XML as a string to storing it as pureXML as easy as executing a single statement (see Figure 3).

pureXML Storage and Retrieval

Along with the XML data type, IBM has delivered an extremely robust enhancement to the SQL language in the form of XML extensions (SQL/XML). In DB2 for z/OS, this extension comes in the form of XPath expressions. Through the IBM pureXML Guide (SC19-2981-01), you can quickly get an overwhelming impression of the programming capabilities possible. A simplified view would be to always think of an XML document as a hierarchy represented as a tree, with a path leading to each node of the tree. XPath expressions are used to declare or reference variables, perform function calls, perform comparisons, index documents, perform searches, and more. Figure 4 contains some examples of XPath expressions.

 

To understand how XPath expressions work with the XML data type, consider the PRODUCT table in the DB2 sample database. This table contains a primary key column Position Identifier (PID) and an XML document in an XML column called DESCRIPTION. Query 1 of Figure 5 reveals the document for a product with a PID of ‘100-100-01’.

DB2 XPath expressions can be used against this data to manipulate it in any way. In the simple example in Query 2 of Figure 5, we use an XMLQUERY function, which returns an XML value from the evaluation of an XPath expression, to return only the product name from the XML document. An XPath expression is used.

5 Pages