XML Schema keys, uniqueness based on ancestor's attribute

Discussion in 'XML' started by Ognen Ivanovski, Jul 15, 2003.

  1. 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.
    Ognen Ivanovski, Jul 15, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Olaf Meyer

    XML schema uniqueness constraints

    Olaf Meyer, Jan 15, 2004, in forum: XML
    Replies:
    0
    Views:
    485
    Olaf Meyer
    Jan 15, 2004
  2. Victor
    Replies:
    3
    Views:
    958
    Martin Honnen
    Feb 6, 2004
  3. Robert Ludewig

    force uniqueness in xml schema

    Robert Ludewig, Jun 28, 2004, in forum: XML
    Replies:
    1
    Views:
    368
    Martin Honnen
    Jun 28, 2004
  4. Robert Ludewig

    force uniqueness with xml schema

    Robert Ludewig, Jun 28, 2004, in forum: XML
    Replies:
    1
    Views:
    418
  5. Adam Gardner
    Replies:
    5
    Views:
    140
    Sebastian Hungerecker
    Nov 19, 2008
Loading...

Share This Page