I have this schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="errorType">
<xs:restriction base="xs:decimal">
<xs:totalDigits value="28"/>
<xs:fractionDigits value="16"/>
<xs:minExclusive value="0"/>
<xs:maxExclusive value="1000000000000"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="TEST">
<xs:complexType>
<xs:sequence>
<xs:element name="newElement" type="errorType" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
And have this xml:
<?xml version="1.0" encoding="UTF-8"?>
<TEST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<newElement>123456789012.5000000000000003</newElement>
<newElement>12345678901.5000000000000003</newElement>
<newElement>1234567890.5000000000000003</newElement>
<newElement>123456789.5000000000000003</newElement>
<newElement>123456789.1234567890123456</newElement>
<newElement>123456789.500000000000003</newElement>
<newElement>1234567890.500000000000003</newElement>
<newElement>12345678901.500000000000003</newElement>
<newElement>123456789012.50000000000003</newElement>
</TEST>
if I validate it using php DOMDocument schemaValidate function i get an error on decimal numbers greater than 27 digits total. Is there any way to overcome this problem?
Complete code:
<?php
function libxml_display_error($error)
{
$return = "<br/>\n";
switch ($error->level) {
case LIBXML_ERR_WARNING:
$return .= "<b>WARNING:</b> $error->message ";
break;
case LIBXML_ERR_ERROR:
$return .= "<b>ERROR:</b> $error->message ";
break;
case LIBXML_ERR_FATAL:
$return .= "<b>FATAL:</b> $error->message ";
break;
}
$return .= " on line <b>$error->line</b>\n";
return $return;
}
function libxml_display_errors() {
$errors = libxml_get_errors();
foreach ($errors as $error) {
print libxml_display_error($error);
}
libxml_clear_errors();
}
$xsd = '<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="errorType">
<xs:restriction base="xs:decimal">
<xs:totalDigits value="28"/>
<xs:fractionDigits value="16"/>
<xs:minExclusive value="0"/>
<xs:maxExclusive value="1000000000000"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="TEST">
<xs:complexType>
<xs:sequence>
<xs:element name="newElement" type="errorType" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>';
$xml ='<?xml version="1.0" encoding="UTF-8"?><TEST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<newElement>123456789012.5000000000000003</newElement>
<newElement>12345678901.5000000000000003</newElement>
<newElement>1234567890.5000000000000003</newElement>
<newElement>123456789.5000000000000003</newElement>
<newElement>123456789.1234567890123456</newElement>
<newElement>123456789.500000000000003</newElement> <!-- VALID -->
<newElement>1234567890.500000000000003</newElement>
<newElement>12345678901.500000000000003</newElement>
<newElement>123456789012.50000000000003</newElement>
</TEST>
';
libxml_use_internal_errors(true);
$xmlObj = new DOMDocument();
$xmlObj->loadXML($xml);
$xmlObj->schemaValidateSource($xsd) ;
print_r (libxml_display_errors());
a) change this label to whatever value you like
b) round the numbers to be smaller than the restriction (probably your numbers are 29 digits including the decimal point)
just acomplish any restriction that the schema requires