Note where the "assert" statement is located
and how attribute of sub element, billto/@country, is used in the XPath expression.
Let's use the "jaxp.TypeInfoWriter" sample program from Xerces2
to validate the XML document to see if the assertion validation rule works or not:
>jdk8x2r jaxp.TypeInfoWriter -xsd11 -a order.xsd -i order.xml
setDocumentLocator(systemId="file:///C:/herong/order.xml", publicI...
startDocument()
startElement(name="order",type="orderType",attributes={{name="cur...
[Error] order.xml:6:38: cvc-complex-type.2.4.a: Invalid content was
^^^ found starting with element 'line'. One of '{billto}' is expected.
[Error] order.xml:6:38: cvc-datatype-valid.1.2.1: '1.0' is not a valid
^^^ value for 'integer'.
[Error] order.xml:6:38: cvc-attribute.3: The value '1.0' of attribute
^^^ 'quantity' on element 'line' is not valid with respect to its
^^^ type, 'positiveInteger'.
startElement(name="line",type="lineType",attributes={{name="sku"...
endElement(name="line")
startElement(name="billto",type="billtoType",attributes={{name="...
endElement(name="billto")
[Error] order.xml:8:36: cvc-identity-constraint.4.2.2: Duplicate key
^^^ value [XMLBOOK] declared for identity constraint "skuKey" of
^^^ element "order".
startElement(name="line",type="lineType",attributes={{name="sku"...
endElement(name="line")
[Error] order.xml:9:9: cvc-assertion.3.13.4.1: Assertion evaluation
^^^ ('(billto/@country eq 'CA' and @currency eq 'CAD') or
^^^ (billto/@country eq 'US' and @currency eq 'USD')') for element
^^^ 'order' with type 'orderType' did not succeed.
endElement(name="order")
endDocument()
I think the assertion validation rule worked ok.
It gives us a good example of how to use "assert" statements for "complexType" custom defined datatypes".
Exercise: Modify order.xml to respect all constraints defined in order.xsd.