This section describes validation rules specified as assertions, which can be viewed as the forth level of constraints that you can force the XML document author to comply.
Validation rules specified as assertions
can be viewed as the forth level of constraints that you can force
the XML document author to comply:
First Level Constraints - XSD built-in datatypes applied on attributes and simple element contents.
Second Level Constraints - User-defined datatypes applied on complex elements.
Third Level Constraints - Identify constraints applied on repeating sub elements.
Obviously, there are a number of areas in this order XML message
that we can use XSD schema to improve the quality:
quantity="1.0" - The quantity should be a positive integer number.
We can use first level constraints like the XSD built-in datatype "positiveInteger" to enforce this rule.
billto country="CA" - The "billto" sub element should be placed before all "line" sub elements.
We can use second level constraints like defining our own complex element type to enforce the sequence
of sub elements.
sku="XMLBOOK" - Any two order lines should not have the same SKU number.
We can use third level constraints like defining a key identify constraint to enforce "sku" values
to be unique.
currency="USD" and country="CA" - The currency "USD" should not be used in bill-to country "CA.
We can use forth level constraints like defining a validation assertion to enforce "currency" values
to be valid in the bill-to country.
The validation assertion could be expressed in XPath as
"(billto/@country eq 'CA' and @currency eq 'CAD')
or (billto/@country eq 'US' and @currency eq 'USD')".
See the next section for the full XSD schema.