Skip to content

XSD Validation

The XSD Validation task accepts an XML input file, and validates it using an XML Schema Definition (XSD) file. It produces an output file, which is a copy of the input file, but with attributes added to any nodes that failed the validation. The attributes provide details of the error that occurred.

A tutorial for writing XSD transforms can be found at W3 Schools.

Settings

Fail On Invalid

Required
When set to True, the task will fail if the XML does not validate against the schema. In most cases this will cause the workflow to stop.

When set to False, the task will succeed even if the XML does not validate against the schema, and the workflow will continue to the next task.

Input File

Required
The name of the XML file to validate against the schema.

Output File

Required
The name of the XML file to save the results of the validation to. The invalid nodes will be have a Validation="false" attribute added, and also an Error attribute stating the reason for the failure. This information can then be used by other tasks in the workflow.

XSD File

Required
The name of the schema file to validate the input file against.

Zynk Settings

See Common Task Settings

Examples

A sample input file is shown below, which is to be validated.

<?xml version="1.0"?>
<Orders>
    <Order>
        <Email>jane.doexexample.com</Email>
        <Total>9.99</Total>
        <Quantity>3</Quantity>
        <Status>Open</Status>
    </Order>
    <Order>
        <Email>[email protected]</Email>
        <Total>50.00</Total>
        <Quantity>5</Quantity>
        <Status>Closed</Status>
    </Order>
    <Order>
        <Email>[email protected]</Email>
        <Total>19.34</Total>
        <Quantity>-2</Quantity>
        <Status>Cancelled</Status>
    </Order>
</Orders>

A sample XSD file is shown below, which will be used to validate the input file.

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Orders">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Order" maxOccurs="unbounded">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Email">
                <xs:annotation>
                  <xs:appinfo>Email must be a valid address, e.g. [email protected].</xs:appinfo>
                </xs:annotation>
                <xs:simpleType>
                  <xs:restriction base="xs:string">
                    <xs:pattern value="[^@]+@[^@]+\.[a-z]+" />
                  </xs:restriction>
                </xs:simpleType>
              </xs:element>
              <xs:element name="Total" type="xs:decimal" />
              <xs:element name="Quantity" type="xs:positiveInteger">
                <xs:annotation>
                  <xs:appinfo>Order quantity must be greater than zero.</xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="Status">
                <xs:simpleType>
                  <xs:restriction base="xs:string">
                    <xs:enumeration value="Open" />
                    <xs:enumeration value="Closed" />
                    <xs:enumeration value="Cancelled" />
                  </xs:restriction>
                </xs:simpleType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

The output file is shown below:

<?xml version="1.0" encoding="utf-8"?>
<Orders>
    <Order>
        <Email Validation="false" Error="Email must be a valid address, e.g. [email protected].">jane.doexexample.com</Email>
        <Total>9.99</Total>
        <Quantity>3</Quantity>
        <Status>Open</Status>
    </Order>
    <Order>
        <Email>[email protected]</Email>
        <Total>50.00</Total>
        <Quantity>5</Quantity>
        <Status>Closed</Status>
    </Order>
    <Order>
        <Email>[email protected]</Email>
        <Total>19.34</Total>
        <Quantity Validation="false" Error="Order quantity must be greater than zero.">-2</Quantity>
        <Status>Cancelled</Status>
    </Order>
</Orders>