简体   繁体   中英

XSD Validators swallow multiple errors in SAX parse

I need to receive a report with all violations of a given XSD 1.0 Schema per element. However, when testing Xerces, Saxon-EE and Altova, all will generate a single error message per SAX element, even if more than one facet is violated. In the example below the text Brand New Œyes violates both the maxLength and pattern facets.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="root" type="rootType"/>
    <xs:complexType name="rootType">
        <xs:sequence>
            <xs:element name="records" type="recordsType"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="recordsType">
        <xs:sequence>
            <xs:element name="record" type="recordType" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="recordType">
        <xs:sequence>
            <xs:element name="title">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:minLength value="1"/>
                        <xs:maxLength value="10"/>
                        <xs:pattern value="[A-Za-z0-9!#$%&amp;'*+/=?^_`{|}~.\- ]+"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element name="artist" type="xs:string"/>
            <xs:element name="genre" type="xs:string"/>
            <xs:element name="year" type="xs:short"/>
        </xs:sequence>
    </xs:complexType>
</xs:schema>
<root>
    <records>
        <record>
            <title>Brand New Œyes</title>
            <artist>Paramore</artist>
            <genre>Punk Rock</genre>
            <year>2011</year>
        </record>
    </records>
</root>

Xerces produces: cvc-pattern-valid: Value 'Brand New Œyes' is not facet-valid with respect to pattern '[A-Za-z0-9?#$%&'*+/=?_ {|}~.- ]+' for type '#AnonType_titlerecordType'. AND cvc-type.3.1.3: The value 'Brand New Œyes' of element 'title' is not valid.`

Saxon-EE produces: The content "Brand New Œyes" of element <title> does not match the required simple type. Value "Brand New Œyes" contravenes the maxLength facet "10" of the type of element title The content "Brand New Œyes" of element <title> does not match the required simple type. Value "Brand New Œyes" contravenes the maxLength facet "10" of the type of element title

If I comment out the pattern in the XSD, then the shallowed error appears in Xerces:

Xerces: cvc-maxLength-valid: Value 'Brand New Œyes' with length = '14' is not facet-valid with respect to maxLength '10' for type '#AnonType_titlerecordType'.

Because Saxon-EE swallows a different error, the pattern , this makes no difference for it.

I think it's unlikely that any of the products you mention provides this capability; certainly Saxon doesn't. I suspect that most users would find the extra error messages unwelcome. There is certainly no requirement in the specification to do this (but then, there is no requirement in the spec to produce any diagnostics at all, beyond a valid/invalid distinction.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM