Ranjit wrote:
This may be quite a dumb question but I have not been able to address
this convincibly. How can I specify restrictions on basic data types in
my xml?
I did some search and came across Schema Component Constraints such as
minInclusive, maxExclusive etc.
But I was wondering if I could refer to them in my xml.
e.g.
<RAM>
<minInclusive>512</minInclusive>
</RAM>
-OR-
<cost maxExclusive = "1000"/>
or something similar.
Can this be done?
You can write an XML schema that defines the structure and restrictions
for your XML instance files, check out
http://www.w3.org/TR/xmlschema-0/
For instance you could define a schema as follows
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="ram" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ram">
<xs:simpleType>
<xs:restriction base="xs:positiveInteger">
<xs:minInclusive value="512" />
<xs:maxInclusive value="1024" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>
and then a validating XML parser would flag the last <ram> element in
the following XML instance file as having a wrong value:
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test20040411Xsd.xml ">
<ram>512</ram>
<ram>768</ram>
<ram>1024</ram>
<ram>256</ram>
</root>
--
Martin Honnen
http://JavaScript.FAQTs.com/