簡體   English   中英

XSD 驗證器吞下 SAX 解析中的多個錯誤

[英]XSD Validators swallow multiple errors in SAX parse

我需要收到一份報告,其中包含每個元素給定 XSD 1.0 架構的所有違規行為。 然而,在測試 Xerces、Saxon-EE 和 Altova 時,所有這些都會為每個 SAX 元素生成一條錯誤消息,即使違反了多個方面。 在下面的示例中,文本Brand New Œyes違反了maxLengthpattern方面。

<?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 生成: cvc-pattern-valid: Value 'Brand New Œyes' is not facet-valid with respect to pattern '[A-Za-z0-9?#$%&'*+/=?_ {|}~”不是有效的。 - ]+' 用於類型 '#AnonType_titlerecordType'。 AND cvc-type.3.1.3:元素“title”的值“Brand New Œyes”無效。

Saxon-EE 產生: 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

如果我注釋掉 XSD 中的pattern ,則淺化錯誤出現在 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'.

因為 Saxon-EE 吞下了一個不同的錯誤, pattern ,這對它來說沒有區別。

我認為您提到的任何產品都不太可能提供這種功能; 撒克遜人當然不會。 我懷疑大多數用戶會發現額外的錯誤消息不受歡迎。 規范中當然沒有要求這樣做(但是,除了有效/無效的區別之外,規范中根本沒有要求產生任何診斷。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM