This XSD schema enforces the XML document to provide a Visa number starting with digit "4".
Here is a sample XML document, visa_card.xml, that should fail the XSD schema validation:
<?xml version="1.0"?>
<!-- visa_card.xml
- Copyright (c) 2014, HerongYang.com, All Rights Reserved.
-->
<visaCard>
<number>5454545454545454</number>
<name>John Gates</name>
</visaCard>
Again, let's use the "jaxp.TypeInfoWriter" sample program from Xerces2
to validate the XML document:
>jdk8x2r jaxp.TypeInfoWriter -xsd11 -a visa_card.xsd -i visa_card.xml
setDocumentLocator(systemId="file:///C:/herong/visa_card.xml", pub...
startDocument()
startElement(name="visaCard",type="visaCardType",attributes={})
startElement(name="number",type="visaNumber",attributes={})
[Error] visa_card.xml:6:35: cvc-assertion.3.13.4.1: Assertion
^^^ evaluation ('starts-with($value, '4')') for element 'number' with
^^^ type 'visaNumber' did not succeed.
endElement(name="number")
startElement(name="name",type="{http://www.w3.org/2001/XMLSchema...
endElement(name="name")
endElement(name="visaCard")
endDocument()
The error message confirms that the "assertion" statement in visa_card.xsd is working.