After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 654696 - xsd:dateTime does not validate dates allowed by xml schema
xsd:dateTime does not validate dates allowed by xml schema
Status: RESOLVED INVALID
Product: libxml2
Classification: Platform
Component: xmlschema
2.7.8
Other Linux
: Normal major
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2011-07-15 18:58 UTC by Michael K Johnson
Modified: 2019-09-16 14:21 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Michael K Johnson 2011-07-15 18:58:22 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
Comment 1 Michael K Johnson 2011-09-02 19:36:53 UTC
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.
Comment 2 zhouzhongyuan 2019-08-17 02:35:04 UTC
  You can see https://www.w3.org/TR/xmlschema11-2/#nt-tzFrag,  the : character seems required in the offset.
Comment 3 Nick Wellnhofer 2019-09-16 14:21:55 UTC
Also see the XML Schema 1.0 spec: https://www.w3.org/TR/xmlschema-2/#dateTime-timezones

The colon is required.