Filling in the Gaps
A range of other functions are available to round out DB2's support for XML. Some of these are operations required in almost any XML environment, while others form the "glue" to more easily use the major functions.
The XML Extender provides two functions for validating XML documents, depending on your choice of schema or DTD validation:
I've mentioned that DTDs are required for some DADs. Schemas are more versatile than DTDs in defining and validating XML documents, and DB2 allows both types to be performed explicitly using either the SVALIDATE(doc, schema) or DVALIDATE(doc, dtd) functions.
Shredding and storing routines, however, will only validate automatically using DTDs.
For explicit validation, the XML document can be provided as a CLOB or as a file system path described in a character string. The schema or DTD can be implied from the XML document, provided as a CLOB, or specified as a file path.
Perform Transformations Using XSL
Transformations demonstrate one of XML's powerful featuresthe ability to convert XML documents into other formats, by writing a formula. The same formula can be used under a range of environments, and DB2 is no exception.
The extender function XSLTransformToFile takes an XML document as a CLOB, an XSL stylesheet as a file or a CLOB, and stores the result of the transform as a file. You can either specify a full file name or just a location, and the system can generate a file name. DB2 Extender can perform validation before running the transform.
Read and Write Files
To pass XML between DB2 and other systems, there is again a choice:
- You can write an application to pass CLOBs to and from the database.
- DB2 Extender provides these functions, which have self-descriptive names: XMLVarcharFromFile, XMLCLOBFromFile, XMLFileFromVarchar, XMLFileFromCLOB
- DB2 v8.1 also provides a range of functions to directly link to IBM's Websphere MQ messaging platform, and many of these functions integrate XML support.