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 |
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.
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.
This configuration property does not apply to fatal errors; validation checking stops on the first fatal error even if this property is set to |
On Validation Failure |
The action to be performed if validation fails:
|
Validation Options |
XSD validation checking options. All options set to
|
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 either0
or1
, 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 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 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
.
<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>
<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>
<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>