GNOME Bugzilla – Bug 654696
xsd:dateTime does not validate dates allowed by xml schema
Last modified: 2019-09-16 14:21:55 UTC
I have a schema that describes XML documents that include dateTime elements that include timezone offsets, and schema validation is failing. http://www.w3.org/TR/xmlschema-2/ seems to be ambiguous on whether timezones are allowed in some places. It explicitly allows them on dates, but does not say that they are not allowed in their more natural place on times; that statement is in the context of a list of deviations from ISO 8601. The list of deviations from ISO 8601 does not include forbidding the numeric offsets in a dateTime. The standard has dateTime examples that explicitly include timezone representation (e.g. 2000-01-12T12:13:14Z). These lead me to the conclusion that timezones (specified as numeric offsets as allowed by ISO 8601) are intended to be allowed in dateTime elements. However, the only timezone specification allowed by libxml2 is the literal Z: $ cat d.xsd <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="Date" type="xsd:dateTime"/> </xsd:schema> $ cat d.xml <?xml version="1.0" encoding="UTF-8" ?> <Date>2011-05-11T12:10:41.0949-0400</Date> $ xmllint --schema d.xsd --noout d.xml d.xml:2: element Date: Schemas validity error : Element 'Date': '2011-05-11T12:10:41.0949-0400' is not a valid value of the atomic type 'xs:dateTime'. d.xml fails to validate $ vi d.xml $ cat d.xml <?xml version="1.0" encoding="UTF-8" ?> <Date>2011-05-11T12:10:41.0949</Date> $ xmllint --schema d.xsd --noout d.xml d.xml validates $ vi d.xml $ cat d.xml <?xml version="1.0" encoding="UTF-8" ?> <Date>2011-05-11T12:10:41.0949Z</Date> $ xmllint --schema d.xsd --noout d.xml d.xml validates
I see that there are more subtleties: If I insert the optional semicolon in the timezone, it validates: $ cat d.xml <?xml version="1.0" encoding="UTF-8" ?> <Date>2011-05-11T12:10:41.0949-04:00</Date> $ xmllint --schema d.xsd --noout d.xml d.xml validates So the real bug seems to be that the : character is required in the offset by libxml2, but it is not required by ISO 8601.
You can see https://www.w3.org/TR/xmlschema11-2/#nt-tzFrag, the : character seems required in the offset.
Also see the XML Schema 1.0 spec: https://www.w3.org/TR/xmlschema-2/#dateTime-timezones The colon is required.