XSD Tutorials - Herong's Tutorial Examples - Version 5.11, by Dr. Herong Yang
Assertion as the Forth Level Constraints
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:
For example, I receive an order XML message, order.xml, from a client system asking to price the order:
<?xml version="1.0"?> <!-- order.xml - Copyright (c) 2014, HerongYang.com, All Rights Reserved. --> <order currency="USD"> <line sku="XMLBOOK" quantity="1.0"/> <billto country="CA"/> <line sku="XMLBOOK" quantity="2"/> </order>
Obviously, there are a number of areas in this order XML message that we can use XSD schema to improve the quality:
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.
Last update: 2014.
Table of Contents
XML Editor and Schema Processor - XMLPad
Java API for XML Processing - JAXP
JAXP - XML Schema (XSD) Validation
Xerces2 Java Parser - Java API of XML Parsers
Introduction of XSD Built-in Datatypes
"string" and Its Derived Datatypes
"decimal" and Its Derived Datatypes
"dateTime" and Its Related Datatypes
Miscellaneous Built-in Datatypes
Facets, Constraining Facets and Restriction Datatypes
"simpleType" - Defining Your Own Simple Datatypes
Identity-Constraints: unique, key and keyref
►Assertion as Custom Validation Rules
►Assertion as the Forth Level Constraints
"assert" Statements for "complexType" Datatype
"assertion" Statements for "simpleType" Datatype
XML Schema Location and Namespace in XML Documents
Overriding Element Types in XML Documents