XSD combining 2 elements

Are you missing a feature? Request its implementation here.
muzicman
Posts: 3
Joined: Fri Aug 20, 2004 4:31 pm
Location: Belgium

XSD combining 2 elements

Post 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>
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post 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
Post Reply