VALIDATED predicate

The VALIDATED predicate tests whether or not the value specified by XML-expression has been validated using the XMLVALIDATE function.

If the value specified is null, the result of the validation constraint is unknown; otherwise, the result of the validation constraint is either true or false. The value you specify must be of type XML.

If the ACCORDING TO XMLSCHEMA clause is not specified, then XML schemas used for validation do not impact the result of the validation constraint.

Read syntax diagramSkip visual syntax diagramXML-expression ISNOTVALIDATED according-to-clause
according-to-clause
Read syntax diagramSkip visual syntax diagramACCORDING TO XMLSCHEMA XML-schema-identificationIN(,XML-schema-identification)
XML-schema-identification
Read syntax diagramSkip visual syntax diagramIDXML-schema-nameURIXML-uri1NO NAMESPACELOCATIONXML-uri2

Description

XML-expression
Specifies the XML value tested, where XML-expression can consist of an XML document, XML content, a sequence of XML nodes, an XML column-name, or an XML correlation-name.

If an XML column-name is specified, the predicate evaluates whether or not XML documents associated with the specified column name have been validated.

See "CREATE TRIGGER" for information about specifying correlation names of type XML as part of triggers.

IS VALIDATED or IS NOT VALIDATED
Specifies the required validation state for the XML-expression operand.

For a constraint that specifies IS VALIDATED to evaluate as true, the operand must have been validated. If an optional ACCORDING TO XMLSCHEMA clause includes one or several XML schemas, the operand must have been validated using one of the identified XML schemas.

For a constraint that specifies IS NOT VALIDATED to evaluate as false, the operand must be in an validated state. If an optional ACCORDING TO XMLSCHEMA clause includes one or several XML schemas, the operand must have been validated using one of the identified XML schemas.

according-to-clause
Specifies one or several XML schemas against which the operand must or must not have been validated. Only XML schemas previously registered with the XML schema repository may be specified.
ACCORDING TO XMLSCHEMA
ID XML-schema-name
Specifies an SQL identifier for the XML schema. The name, including the implicit or explicit SQL schema qualifier, must uniquely identify an existing XML schema in the XML schema repository at the current server. If no XML schema by this name exists in the implicitly or explicitly specified SQL schema, an error is returned (SQLSTATE 42704).
URI XML-uri1
Specifies the target namespace URI of the XML schema. The value of XML-uri1 specifies a URI as a character string constant that is not empty. The URI must be the target namespace of a registered XML schema (SQLSTATE 4274A) and, if no LOCATION clause is specified, it must uniquely identify the registered XML schema (SQLSTATE 4274B).
NO NAMESPACE
Specifies that the XML schema has no target namespace. The target namespace URI is equivalent to an empty character string that cannot be specified as an explicit target namespace URI.
LOCATION XML-uri2
Specifies the XML schema location URI of the XML schema. The value of XML-uri2 specifies a URI as a character string constant that is not empty. The XML schema location URI, combined with the target namespace URI, must identify a registered XML schema (SQLSTATE 4274A), and there must be only one such XML schema registered (SQLSTATE 4274B).

Examples

Example 1: 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 2: 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)
Example 3: Assume that you want to select only those rows from table T1 with XML column XMLCOL that have been validated with the XML schema URI http://www.posample.org.

   SELECT XMLCOL FROM T1 
     WHERE XMLCOL IS VALIDATED 
      ACCORDING TO XMLSCHEMA URI 
      'http://www.posample.org'