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 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With