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>5 12</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="unbo unded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ram">
<xs:simpleTyp e>
<xs:restricti on base="xs:positi veInteger">
<xs:minInclusiv e value="512" />
<xs:maxInclusiv e 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:noNamespace SchemaLocation= "test20040411Xs d.xml">
<ram>512</ram>
<ram>768</ram>
<ram>1024</ram>
<ram>256</ram>
</root>
--
Martin Honnen
http://JavaScript.FAQTs.com/