Page 1 of 1

XSD combining 2 elements

Posted: Fri Aug 20, 2004 7:06 pm
by muzicman
Hi,
I've got al list of possible combinations of brands and models
I want to use xsd to verify if the combination is ok
can I do this using XSD?
thanks

example:
xsd:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="CAR">
<xs:complexType>
<xs:all>
<xs:element name="BRAND" />
<xs:element name="MODEL" />
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>

xml:
<CAR>
<BRAND>MASERATI</BRAND>
<MODEL>DB9</BRAND>
</CAR>

Posted: Sat Aug 21, 2004 5:13 am
by george
Hi,

AFAIK you cannot do that with XML Schema. You can check only that an element contains values in a specified set if you restrict the values using enumeration for instance:

Code: Select all


<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="CAR">
<xs:complexType>
<xs:all>
<xs:element name="BRAND">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="MASERATI"/>
<!-- add all your possible values here -->
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="MODEL">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="DB9"/>
<!-- add all your possible values here -->
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
Oxygen also supports Relax NG schemas. Relax NG should allow you to check brands/models. Also as an alternative you may consider writting an XSLT to check this.

Best Regards,
George