The XML Validation filter is used to validate XML documents against an XML Schema Definition Language (XSD) schema. The filter returns the original XML message if the message is valid and includes the option to route to the error connector, to continue processing the message, or to return an XML document with full error information if the message is invalid. There are three levels of validation error (warn, error and fatal error) which you can set as the minimum validation failure level. During message validation the filter counts the number of errors which have occurred, in total and for each level of error, and stores these values in message properties.

The XML Schema Definition Language (XSD) is an XML language for describing and constraining the content of XML documents. XSD has advantages over DTD that include:

  • Because XSD is written in XML, there is no need for a special parser.
  • XSD defines a richer set of data types such as booleans, numbers, dates and times, and currencies.
  • XSD makes it easier to validate documents based on Namespace (used to qualify element and attribute names by associating them with Namespace identified by URI references. Namespace prevents identically custom-named tags that may be used in different XML documents from being read the same way), something DTDs cannot do.

Refer to XML Schema for details.

Configuration Properties

Property

Description

Maximum Concurrency

The maximum level of concurrency for this filter. A setting of 0 (zero) means unlimited. Limiting the level of concurrency limits memory usage. Refer to Maximum Concurrency for details.

W3C XML Schema

The W3C XML Schema to be used to validate the input XML message.

Minimum Failure Level

The minimum level that the filter decides the message is invalid.

  • Warn
  • Error
  • Fatal Error (default)

Refer to the Continue Checking On Error configuration property for details on usage.

Continue Checking On Error

Whether to continue validating on encountering a minimum failure level.

  • Enabled - the filter continues validation checking to the end of the message, even if a minimum failure level error occurs, and decides the message validation failure after the checking is completed.
  • Disabled (default) - the filter stops checking as soon as a minimum failure level error occurs.

This configuration property does not apply to fatal errors; validation checking stops on the first fatal error even if this property is set to True.

On Validation Failure

The action to be performed if validation fails:

  • Send to error connector (default) - the message is sent to the error connector.
  • Continue processing on route - the message is routed to the next filter or output communication point to continue processing the message.
  • Send error report to route - the body of the message is replaced by an XML document containing full error information and the original message and the message is routed to the next filter or output communication point.

    Sample error report as output by 'Send error report to route'.
    <?xml version="1.0" ?>
    <XSDValidationReport>
       <Errors>
         <Error>TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace.</Error>
         <Error>cvc-elt.1: Cannot find the declaration of element 'HeadCount'. </Error>
         <Error>TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace.</Error>
       </Errors>
       <FatalErrors>
         <FatalError>The element type "Name" must be terminated by the matching end-tag "&lt;/Name&gt;".</FatalError>
       </FatalErrors>
       <OriginalMessage>
         &lt;HeadCount xmlns:xsi="http://www.w3.org/
         2001/XMLSchema-instance"xsi:schemaLocation=
         "xsdHeadCount HeadCount.xsd"&gt;
         &lt;Name&gt;Waldo Pepper&lt;/PName&gt;
         &lt;RName&gt;Red Pepper&lt;/RName&gt;
         &lt;/HeadCount&gt;
       </OriginalMessage>
    </XSDValidationReport> 

Validation Options

XSD validation checking options. All options set to False by default. If a particular checking option needs to be turned on, then select the option and set its value to True. The checking options are:

  • Full schema constraint checking - enable full schema grammar constraint checking, including any checking which may be time-consuming or memory intensive. Particle unique attribution constraint checking and particle derivation restriction checking are controlled by this option. This option checks the schema grammar itself for additional errors that are time-consuming or memory intensive. It does not affect the level of checking performed on document instances that use schema grammars.
  • Warn on redeclared duplicate attribute - report a warning for duplicate attribute declaration.
  • Warn on redeclared duplicate entity - report a warning for duplicate entity declaration.
  • Allow Java encoding names in XMLDecl and TextDecl line - if set to True, the encoding of the file may be specified as a Java encoding name as well as the standard ISO encoding name. Be aware that other XML parsers may not be able to use Java encoding names. If set to False, an error will be generated if Java encoding names are used.

Published Properties

Published properties for the XSD Validator filter are:

  • WarnCount - the number of warnings which occurred during validation checking.
  • ErrorCount - the number of errors which occurred during validation checking.
  • FatalErrorCount - the number of fatal errors which occurred during validation checking. FatalErrorCount is either 0 or 1, because the filter stops validation checking on the first fatal error.
  • TotalErrorCount - the total number of errors which occurred during validation checking. Essentially it is the sum of property values of WarnCount, ErrorCount and FatalErrorCount.

Examples

XML Message with No Namespace to Be Validated

The following example shows an XML message and XML schema to be validated against where no Namespace is used:

XML message (with no namespace) to be validated
<?xml version="1.0" encoding="utf-8"?>
<book isbn="0836217462">
  <title>Being a Dog Is a Full-Time Job</title>
  <author>Charles M. Schulz</author>
  <character>
    <name>Snoopy</name>
    <friend-of>Peppermint Patty</friend-of>
    <since>1950-10-04</since>
    <qualification>extroverted beagle</qualification>
  </character>
  <character>
    <name>Peppermint Patty</name>
    <since>1966-08-22</since>
    <qualification>bold, brash and tomboyish</qualification>
  </character>
</book>
XML schema (with no namespace) to be validated against
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="book">
     <xs:complexType>
       <xs:sequence>
         <xs:element name="title" type="xs:string"/>
         <xs:element name="author" type="xs:string"/>
         <xs:element name="character" minOccurs="0" maxOccurs="unbounded">
           <xs:complexType>
             <xs:sequence>
               <xs:element name="name" type="xs:string"/>
               <xs:element name="friend-of" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
               <xs:element name="since" type="xs:date"/>
               <xs:element name="qualification" type="xs:string"/>
             </xs:sequence>
           </xs:complexType>
         </xs:element>
       </xs:sequence>
       <xs:attribute name="isbn" type="xs:string"/>
    </xs:complexType>
  </xs:element>
</xs:schema>

XML Message with Namespace to Be Validated

This example shows an XML message to be validated and multiple XML schemas to be validated against where namespaces are used. Note that the actual document of the schema with a target namespace of urn:bookstore‑schema is located at book.xsd and the actual document of the schema with a target namespace of urn:tapestore-schema is located at tape.xsd.

XML message (with namespace) to be validated
<pb:main xmlns:pb="urn:bookstore-schema">
  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns="urn:dvdstore-schema" targetNamespace="urn:dvdstore-schema">
    <xs:element name="dvd" type="xs:string" />
  </xs:schema>

  <pb:book price="7.99" xmlns:pb="urn:bookstore-schema"
  xsi:schemaLocation="urn:bookstore-schema book.xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    The Autobiography of Benjamin Franklin
  </pb:book>

  <pd:dvd xmlns:pd="urn:dvdstore-schema">
    The Godfather
  </pd:dvd>

  <pt:tape xmlns:pt="urn:tapestore-schema"
  xsi:schemaLocation="urn:tapestore-schema tape.xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    Il Postino
  </pt:tape>
</pb:main>
XML schema with no namespace, book.xsd, to be validated against
<xs:schema xmlns="urn:bookstore-schema"
targetNamespace="urn:bookstore-schema"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="main">
  </xs:element>
  <xs:element name="book">
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="xs:string">
          <xs:attribute name="price" type="xs:decimal"/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element> 
XML schema with no namespace, tape.xsd, to be validated against
<xs:schema xmlns="urn:tapestore-schema"
targetNamespace="urn:tapestore-schema"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <xs:element name="tape" type="xs:string"/>
</xs:schema>