I am having a bit of a problem with empty values failing validation on one server, but it works on all my other servers. The problem occurs on a newer PHP version (5.3.8) and works on a slightly older version (5.2.4).
Here are a couple of isolated elements which fail:
XML Input:
<clbburnfuelbias></clbburnfuelbias>
<clbburntimebias></clbburntimebias>
XSD Validation:
<xs:element name="clbburnfuelbias" type="data-fuelbias"/>
<xs:element name="clbburntimebias" type="data-timebias"/>
<xs:simpleType name="data-fuelbias">
<xs:restriction base="xs:integer">
<xs:minInclusive value="-9900"/>
<xs:maxInclusive value="9900"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="data-timebias">
<xs:restriction base="xs:integer">
<xs:minInclusive value="-59"/>
<xs:maxInclusive value="59"/>
</xs:restriction>
</xs:simpleType>
Error:
Error 1824: Element ‘clbburnfuelbias’: The value is not a valid value
of the atomic type ‘data-fuelbias’. Error 1824: Element
‘clbburntimebias’: The value is not a valid value of the atomic type
‘data-timebias’.
Using the exact same input and XSD files on different servers running 5.2.4 I get no errors and the xml is valid.
I have tried adding minOccurs=”0″ to the elements, I have tried specifying nullable=”true” as well but still get the errors.
UPDATE:
It appears that null values are ignored on my servers using PHP 5.2.4, and rejected using 5.3.8. A work around that I’ve used which was suggested is to use a union of two definitions, one for the integer type, and one for a null value:
XSD:
<xs:element name="clbburnfuelbias" minOccurs="0">
<xs:simpleType>
<xs:union memberTypes="data-fuelbias null-string"/>
</xs:simpleType>
</xs:element>
<xs:simpleType name="data-fuelbias">
<xs:restriction base="xs:integer">
<xs:minInclusive value="-9900"/>
<xs:maxInclusive value="9900"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="null-string">
<xs:restriction base="xs:string">
<xs:length value="0"/>
</xs:restriction>
</xs:simpleType>
Making an element optional (
minOccurs="0") doesn’t make its contents a wildcard. If the element appears, it must match the declared type.Making an element nillable (
nillable="true") allows the element to be empty if it has thexsi:nil="true"attribute, wherexmlns:xsi="http://www.w3.org/2001/XMLSchema-instance":You may also use a union type, which only has the same meaning for validation purposes: