Saturday, March 29, 2008

XML minInclusive and maxInclusive

Problem: I originally built a xsd Schema for a xml file. The element I was designing was a "cpostcode" that has a restriction of 2000-7999. This was my code and then the error.

Original Code

<xsd:element name = "cpostcode">
<xsd:simpletype>
<xsd:mininclusive value = "2000">
<xsd:maxinclusive value = "7999">
</xsd:simpleType>
</xsd:element>
Error was complaining about minInclusive tag.


Solution: A restriction tag is needed for minInclusive and needs a attribute type.

Solution code is as follows
<xsd:element name = "cpostcode">
<xsd:simpletype>
<xsd:restriction base="xsd:integer">
<xsd:mininclusive value = "2000">
<xsd:maxinclusive value = "7999">
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
I added a restriction type with a base of xsd:integer around the minInclusive and maxInclusive tags.