Validating XML documents
To validate a particular XML document, you must explicitly invoke the XMLVALIDATE function.
About this task
You typically validate XML data during an insert or update operation by using the XMLVALIDATE function. The XMLVALIDATE function validates an XML value against an XML schema or against the XML schema that is obtained from the schema specification in the instance document.
When you insert or update an XML column in a nickname and use the XMLVALIDATE function, validation occurs on the federated server. The federated server then serializes the data and sends it to the data source. During serialization, any data type annotations added by XMLVALIDATE are not preserved.
Invoke the XMLVALIDATE function as part of an SQL statement.
- If the XMLVALIDATE is called without a schema specification, the schema is determined based on the schemaLocation attribute in the instance document. If no schema information exists, an error message is issued.
- If XMLVALIDATE is called with a registered schema or with a specific Uniform Resource Identifier (URI), validation is performed against that specific schema. If an external schema is specified, the external schema overwrites the internal schema specification.
Example: Validate an XML document using the XML schema named MYSCHEMA.MYDOCUMENTS:
If the XML schema that is associated with the SQL identifier MYSCHEMA.MYDOCUMENTS exists in the XML repository, the input XML value is validated.
INSERT INTO NNXML1(XMLCOL) VALUES ( XMLVALIDATE( ? ACCORDING TO XMLSCHEMA ID MYSCHEMA.MYDOCUMENTS ) )