O
Ognen Ivanovski
Is the following constraint possible to be expressed with XML Schema
(and how):
Suppose we have a document in the form
<car type="ford">
<part name="door"/>
<part name="ashtray"/>
</car>
<car type="bmw">
<part name="door"/>
....
</car>
Is it possible to define a key for the parts of a car such that the key
will include the type of the car too.
In this way the door of the BMW will be unique because a) it's a door
and b) it is part of the BMW and will differ from the door of the Ford
since it is not defined in the ford.
Say the schema is
<xs:schema>
<xs:element name="car">
<xs:complexType>
<xs:sequence>
<xs:element name="part" maxOccurs="unbounded">
<xs:complexType>
<xs:complexContent>
<xs:attribute name="name" type="xs:string"/>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
So i want a key definition that uniquely identifies the element "part"
of the element "car" by using the part's "name" attribute *and* the
car's "name" attribute.
I thought something in the line of
<xs:key name="partKey">
<xs:selector xpath="car/part"/>
<xs:field xpath="@name"/>
<xs:field xpath="../@name"/>
</xs:key>
BUT, the XML Schema recommendation's restricted XPATH usage in key
definitions forbids that.
Any other ideas?
O.
(and how):
Suppose we have a document in the form
<car type="ford">
<part name="door"/>
<part name="ashtray"/>
</car>
<car type="bmw">
<part name="door"/>
....
</car>
Is it possible to define a key for the parts of a car such that the key
will include the type of the car too.
In this way the door of the BMW will be unique because a) it's a door
and b) it is part of the BMW and will differ from the door of the Ford
since it is not defined in the ford.
Say the schema is
<xs:schema>
<xs:element name="car">
<xs:complexType>
<xs:sequence>
<xs:element name="part" maxOccurs="unbounded">
<xs:complexType>
<xs:complexContent>
<xs:attribute name="name" type="xs:string"/>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
So i want a key definition that uniquely identifies the element "part"
of the element "car" by using the part's "name" attribute *and* the
car's "name" attribute.
I thought something in the line of
<xs:key name="partKey">
<xs:selector xpath="car/part"/>
<xs:field xpath="@name"/>
<xs:field xpath="../@name"/>
</xs:key>
BUT, the XML Schema recommendation's restricted XPATH usage in key
definitions forbids that.
Any other ideas?
O.