3
votes

Whether the 25 digits are decimal and integers or just integers, DOMDocument::schemaValidate() fires a warning, return false, and libxml_get_errors(); captures the next errors:

PHP snippet:

$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() Generated Errors:

Error 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

Error 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

Valid schema (invalid XML only):

<?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>

Invalid schema: WARNING + Libxml internal errors of invalid schema

<?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 version: 5.5.20

Libxml version: 2.9.2

1

1 Answers

3
votes

According to W3C XML Schema Part 2: Datatypes Second Edition, libxml2 can limit the range of maxInclusive because it is allowed to limit the range of the value space of xs:decimal...

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.