当 maxInclusive 有 25 位或更多位时,为什么 Libxml 说无效架构?

Why Libxml says invalid schema when maxInclusive have 25 or more digits?

无论 25 位数字是小数和整数还是只是整数,DOMDocument::schemaValidate() 都会发出警告,return 错误,libxml_get_errors(); 会捕获下一个错误:

PHP 片段:

$DD = new DOMDocument('1.0', 'ISO-8859-1');
$DD -> loadXML('<?xml version ="1.0" encoding="ISO-8859-1"?><a></a>');
libxml_use_internal_errors(true);
$old_libxml_disable_entity_loader = libxml_disable_entity_loader(false);
$DD -> schemaValidate(__DIR__ . '/schemas/schema.xsd'); // WARNING
libxml_disable_entity_loader($old_libxml_disable_entity_loader);
$errors = libxml_get_errors();

foreach ($errors as $error) { // PRINT ERRORS
    echo $error -> code . '<br>';
    echo $error -> message . '<br>';
}

DOMDocument::schemaValidate() 生成的错误:

错误 1824:

Element '{http://www.w3.org/2001/XMLSchema}maxInclusive': '9999999999999999999999999' is not a valid value of the atomic type 'xs:decimal'. in /path/schema.xsd on line X

错误 1717:

Element '{http://www.w3.org/2001/XMLSchema}maxInclusive': The value '9999999999999999999999999' of the facet does not validate against the base type '{http://www.w3.org/2001/XMLSchema}decimal'. in /path/schema.xsd on line X

有效架构(仅 XML 无效):

<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema
    targetNamespace="http://www.lala.com/la"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:la="http://www.lala.com/la"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">

    <xs:simpleType name="AmountType">
        <xs:restriction base="xs:decimal">
            <xs:totalDigits value="100"/>
            <xs:fractionDigits value="20"/>
            <xs:maxInclusive value="999999999999999999999999"/><!-- 24 DIGITS -->
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

无效架构:警告 + 无效架构的 Libxml 内部错误

<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema
    targetNamespace="http://www.lala.com/la"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:la="http://www.lala.com/la"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">

    <xs:simpleType name="AmountType">
        <xs:restriction base="xs:decimal">
            <xs:totalDigits value="100"/>
            <xs:fractionDigits value="20"/>
            <xs:maxInclusive value="9999999999999999999999999"/><!-- 25 DIGITS -->
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

PHP版本:5.5.20

Libxml 版本:2.9.2

根据W3C XML Schema Part 2: Datatypes Second Edition,libxml2可以限制maxInclusive的范围,因为允许限制xs:decimal的值space的范围...

4.3.7 maxInclusive:

[Definition:] maxInclusive is the ·inclusive upper bound· of the ·value space· for a datatype with the ·ordered· property. The value of maxInclusive ·must· be in the ·value space· of the ·base type·.

3.2.3 decimal

Note: All ·minimally conforming· processors ·must· support decimal numbers with a minimum of 18 decimal digits (i.e., with a ·totalDigits· of 18). However, ·minimally conforming· processors ·may· set an application-defined limit on the maximum number of decimal digits they are prepared to support, in which case that application-defined maximum number ·must· be clearly documented.