XML Schema: comparing to date elements
I have an XML file like this:
<?xml version="1.0" encoding="UTF-8"?>
<items>
<item id="1">
<valid_from>2010-07-09</valid_from>
<valid_to>2010-07-12</valid_to>
</item>
<item id="2">
<valid_from>2010-07-09</valid_from>
<valid_to>2009-07-12</valid_to>
</item>
</items>
Is it possible开发者_如何学C to define an XML Schema thats saying the valid_from element has to be older then the valid_to element?
You can use <xs:assert>
(or alternatively <xs:report>
) to do that:
<xs:complexType name="ItemType">
<xs:sequence>
<xs:element name="valid_from" type="xs:date" />
<xs:element name="valid_to" type="xs:date" />
</xs:sequence>
<xs:assert test="valid_from lt valid_to" />
</xs:complexType>
But this requires XML Schema 1.1
精彩评论