XSD Tutorials - Herong's Tutorial Examples - v5.23, by Herong Yang
jaxp.TypeInfoWriter as an XSD 1.1 Validation Tool
This section provides a tutorial example on how to use sample program jaxp.TypeInfoWriter as an XSD 1.1 validation tool. It prints out element type information, while it is parsing through the XML document. Error messages are printed out where and when they occurred.
If you want to see XSD 1.1 errors printed inside the XML element structure, you can try the other sample program, jaxp.TypeInfoWriter:
herong> java_xerces jaxp.TypeInfoWriter -xsd11 -i xsd11_datatype_test.xml setDocumentLocator(systemId="file:///C:/herong ^^^ /xsd11_datatype_test.xml", publicId=null) startDocument() startElement(name="XSD11_Datatype_Test",type= ^^^ "#AnonType_XSD11_Datatype_Test",attributes={{name= ^^^ "{http://www.w3.org/2001/XMLSchema-instance} ^^^ noNamespaceSchemaLocation",type="{http://www.w3.org/2001 ^^^ /XMLSchema}anyURI",id="false",specified="true"}}) startElement(name="AnyAtomicType",type="{http://www.w3.org/2001 ^^^ /XMLSchema}anyAtomicType",attributes={}) endElement(name="AnyAtomicType") startElement(name="AnyAtomicType",type="{http://www.w3.org/2001 ^^^ /XMLSchema}anyAtomicType",attributes={}) endElement(name="AnyAtomicType") startElement(name="AnyAtomicType",type="{http://www.w3.org/2001 ^^^ /XMLSchema}anyAtomicType",attributes={}) endElement(name="AnyAtomicType") startElement(name="AnyAtomicType",type="{http://www.w3.org/2001 ^^^ /XMLSchema}anyAtomicType",attributes={}) startElement(name="b",type="{http://www.w3.org/2001/XMLSchema} ^^^ anyType",attributes={{name="size",type=null,id="false", ^^^ specified="true"}}) endElement(name="b") [Error] xsd11_datatype_test.xml:17:67: cvc-type.3.1.2: Element ^^^ 'AnyAtomicType' is a simple type, so it must have no element ^^^ information item [children]. endElement(name="AnyAtomicType") startElement(name="DateTimeStamp",type="{http://www.w3.org/2001 ^^^ /XMLSchema}anyAtomicType",attributes={}) endElement(name="DateTimeStamp") startElement(name="DateTimeStamp",type="{http://www.w3.org/2001 ^^^ /XMLSchema}anyAtomicType",attributes={}) [Error] xsd11_datatype_test.xml:23:51: cvc-datatype-valid.1.2.1: '?' ^^^ is not a valid value for 'dateTimeStamp'. [Error] xsd11_datatype_test.xml:23:51: cvc-type.3.1.3: The value ^^^ ' ? ' of element 'DateTimeStamp' is not valid. endElement(name="DateTimeStamp") startElement(name="DayTimeDuration",type="{http://www.w3.org/2001 ^^^ /XMLSchema}anyAtomicType",attributes={}) endElement(name="DayTimeDuration") startElement(name="DayTimeDuration",type="{http://www.w3.org/2001 ^^^ /XMLSchema}dayTimeDuration",attributes={}) [Error] xsd11_datatype_test.xml:29:65: cvc-datatype-valid.1.2.1: ^^^ 'P1Y2M3DT5H20M30.123S' is not a valid value for 'dayTimeDuration'. [Error] xsd11_datatype_test.xml:29:65: cvc-type.3.1.3: The value ^^^ ' P1Y2M3DT5H20M30.123S ' of element 'DayTimeDuration' is not ^^^ valid. endElement(name="DayTimeDuration") startElement(name="YearMonthDuration",type="{http://www.w3.org/2001 ^^^ /XMLSchema}yearMonthDuration",attributes={}) endElement(name="YearMonthDuration") startElement(name="YearMonthDuration",type="{http://www.w3.org/2001 ^^^ /XMLSchema}yearMonthDuration",attributes={}) [Error] xsd11_datatype_test.xml:35:69: cvc-datatype-valid.1.2.1: ^^^ 'P1Y2M3DT5H20M30.123S' is not a valid value for ^^^ 'yearMonthDuration'. [Error] xsd11_datatype_test.xml:35:69: cvc-type.3.1.3: The value ^^^ ' P1Y2M3DT5H20M30.123S ' of element 'YearMonthDuration' is ^^^ not valid. endElement(name="YearMonthDuration") endElement(name="XSD11_Datatype_Test") endDocument()
Excellent! jaxp.TypeInfoWriter is good XSD 1.1 validation tool. It prints out element type information, while it is parsing through the XML document. Error messages are printed out where and when they occurred.
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
Installing Xerces2 Java Parser for XSD 1.1
Verify Installation of Xerces2
Xerces2 Sample Program dom.Counter
dom.Counter Validating XML with Associated XSD
dom.GetElementsByTagName and dom.Writer
sax.DocumentTracer and sax.Writer
Examples of XSD and XML Files with Errors
sax.Writer Reporting Errors Embedded in XML Structure
XSD 1.1 not Supported by sax.Writer
XSD 1.1 Supported by jaxp.SourceValidator
Examples of XSD 1.1 and XML Files with Errors
►jaxp.TypeInfoWriter as an XSD 1.1 Validation Tool
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
XML Schema Location and Namespace in XML Documents
Overriding Element Types in XML Documents