Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Schema: comparing to date elements

Tags:

date

xml

xsd

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?

like image 453
DerKlops Avatar asked Jul 21 '10 13:07

DerKlops


1 Answers

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

like image 136
svick Avatar answered Sep 24 '22 12:09

svick