XML validation is the process of determining whether the structure, content, and data types of an XML document are valid.
In addition, XML validation adds type annotations to element nodes, attribute nodes and atomic values, and strips off ignorable whitespace in the XML document. Validation is optional, but highly recommended.
You can use the XMLVALIDATE function to validate an XML document. Usually, you invoke XMLVALIDATE when you insert or update an XML document in a DB2 database. However, you can also invoke XMLVALIDATE on an XML document that is not in a database.
Note that you can validate your XML documents against XML schemas only. You cannot validate an XML document against a DTD.
Before you can invoke XMLVALIDATE, all schema documents that make up an XML schema must be registered in the built-in XML schema repository (XSR). An XML schema provides the rules for a valid XML document.
The VALIDATED predicate checks that the value specified by column-name, which must have data type XML, has already been validated using the XMLVALIDATE function. The XML schema that was used for validation does not impact the result.
The VALIDATED predicate is only supported in a Unicode database with a single database partition.
If the value of column-name is null, the result of the predicate is unknown; otherwise, the result is either true or false. The result of the predicate is true if the value of column-name is not null and has been validated. The result of the predicate is false if the value of column-name is not null and has not been validated.
Example: Assume that column XMLCOL is defined in table T1. Retrieve only the XML values that have been validated by any XML schema:
SELECT XMLCOL FROM T1 WHERE XMLCOL IS VALIDATED
Example: Assume that column XMLCOL is defined in table T1. Enforce the rule that values cannot be inserted or updated unless they have been validated:
ALTER TABLE T1 ADD CONSTRAINT CK_VALIDATED CHECK (XMLCOL IS VALIDATED)