∟sax.Writer Reporting Errors Embedded in XML Structure
This section provides a tutorial example showing sax.Writer reporting XSD validation errors embedded inside XML structure.
Now let's rerun sax.Writer on dictionary_invalid_xsd.xml
and see how it reports those errors:
>jdk8x2r sax.Writer -v -s dictionary_invalid_xsd.xml
<?xml version="1.0" encoding="UTF-8"?>
<dictionary xsi:noNamespaceSchemaLocation="dictionary.xsd">
[Error] dictionary_invalid_xsd.xml:7:22: cvc-datatype-valid.1.2.1:
^^^ 'yes' is not a valid value for 'boolean'.
[Error] dictionary_invalid_xsd.xml:7:22: cvc-attribute.3: The value
^^^ 'yes' of attribute 'acronym' on element 'word' is not valid with
^^^ respect to its type, 'boolean'.
<word acronym="yes">
[Error] dictionary_invalid_xsd.xml:8:10: cvc-complex-type.2.4.a:
^^^ Invalid content was found starting with element 'names'. One of
^^^ '{name}' is expected.
<names>XML</names>
<definition reference="Herong's Notes">eXtensible Markup
Language.</definition>
[Error] dictionary_invalid_xsd.xml:11:31: cvc-pattern-valid: Value
^^^ '23-Dec-2003' is not facet-valid with respect to pattern
^^^ '\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}' for type
^^^ '#AnonType_dateupdateType'.
[Error] dictionary_invalid_xsd.xml:11:31: cvc-attribute.3: The value
^^^ '23-Dec-2003' of attribute 'date' on element 'update' is not valid
^^^ with respect to its type, '#AnonType_dateupdateType'.
<update date="23-Dec-2003"></update>
</word>
<word symbol="true">
<name><</name>
<definition>Mathematical symbol representing the "less than"
logical operation, like: 1<2.</definition>
<definition>Reserved symbol in XML representing the beginning of
tags, like: <![CDATA[<p>Hello world!</p>]]>
</definition>
[Error] dictionary_invalid_xsd.xml:20:33: cvc-complex-type.3.2.2:
^^^ Attribute 'editor' is not allowed to appear in element 'update'.
<update editor="Herong Yang"></update>
</word>
[Error] dictionary_invalid_xsd.xml:22:36: cvc-datatype-valid.1.2.1:
^^^ 'no' is not a valid value for 'boolean'.
[Error] dictionary_invalid_xsd.xml:22:36: cvc-attribute.3: The value
^^^ 'no' of attribute 'symbol' on element 'word' is not valid with
^^^ respect to its type, 'boolean'.
<word acronym="false" symbol="no">
<name>extensible</name>
<definition>Capable of being extended.</definition>
</word>
</dictionary>
Really nice! All errors are reported where they occurred.