XML Schema keys, uniqueness based on ancestor's attribute

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top