Registering XML Schema to IBM DB2 pureXML

Target Audience: DBA, DB Developers
What you should know: XML, XML Schema, Understanding of IBM DB2 pureXML

DB2 is unrivaled in its ability to manage both relational and XML data, enabling strong runtime performance and high levels of development time and cost savings. By integrating XML data intact into a relational database structure, users can take full advantage of DB2’s relational data management features.

XML Document Validation

Using your file system, XML documents can be validated using Document Type Definition (DTD) or XML Schema Document (XSD). The validation is done using the namespace declaration in the XML document.

XML Column Validation

XML (column) validation is the process of determining whether the structure, content, and data types of an XML (column) document are valid according to an XML schema.

When you plan to make use of pureXML features you should consider XML document validation when you insert into XML columns. You can register schema document (XSD) to DB2 and that can be identified using schema id. For example, the following XML schema document contains definitions for element called isbn:

<?xml version="1.0" ?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://library.com/isbn-schema" xmlns:tns="http://library.com/isbn-schema">
<complexType name="isbnType">
<sequence>
<element name="bktitle" type="string"/>
<element name="author" type"string" />
</sequence>
</complexType>
<element name="isbn" type="tns:isbnType" />
</schema>

Suppose, the above file is located in /home/theuser/ibm/schema_for_isbn.xsd then, the CLP command for registering above schema is as follows
REGISTER XMLSCHEMA 'schema_for_isbn.xsd' FROM 'file:////home/theuser/ibm/schema_for_isbn.xsd' AS DB2INST1.LIBRARY_BOOK_SCHEMA;
Then issue the following command to validate the XML schema and activate it:
COMPLETE XMLSCHEMA DB2INST1.LIBRARY_BOOK_SCHEMA


Reference
Managing XML Schema in IBM DB2

Permanent link to this article: https://blog.openshell.in/2010/12/registering-xml-schema-to-ibm-db2-purexml/

Leave a Reply

Your email address will not be published.