problems with key/keyref and complex-type inheritance

Discussion in 'XML' started by peterpeter, Feb 12, 2007.

  1. peterpeter

    peterpeter Guest

    Hi.

    There is a XML schema problem that I have with key/keyref:

    I have a complex type "AExtended" which inherits from a base type
    "ABase". Both are allowed to be instantiated under the "Root" element
    by declaring an element of the base class with name "A" and either
    "xsi:type=ABase" or "xsi:type=AExtended".

    I want to have type safety for the reference "Ref_to_AExtended" from
    another type/element "B" by using key/keyref. A reference to an
    instance of type "ABase" is not allowed. So, there should be a key
    definition for the @key attribute of type "AExtended" and a keyref
    definition between this key and the "Ref_to_AExtended" element of type
    "B".

    But there's a problem: The XPath expressions in key/keyref do not
    allow to contain tests like [@type="AExtended"]. How can I reach the
    instance element of type "AExtended" with my XPath? Or is there
    another solution?

    Thanks for helpful answers...

    PETER

    Here is the schema:

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="Root" type="Root"/>
    <xs:complexType name="Root">
    <xs:sequence>
    <xs:element name="A" type="ABase"
    minOccurs="0"
    maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="ABase">
    <xs:attribute name="key" type="xs:ID" use="required"/
    >

    </xs:complexType>
    <xs:complexType name="AExtended">
    <xs:complexContent>
    <xs:extension base="ABase"/>
    </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="B">
    <xs:sequence>
    <xs:element name="Ref_to_AExtended"
    type="xs:IDREF"/>
    </xs:sequence>
    </xs:complexType>
    </xs:schema>

    And here is an instance example:

    <?xml version="1.0" encoding="UTF-8"?>
    <Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="test.xsd">
    <A xsi:type="AExtended" key="key1"/>
    <B>
    <Ref_to_AExtended>key1</Ref_to_AExtended>
    </B>
    </Root>

    I planned these key/keyref to be within my instance element
    declaration of the Root:

    <xs:element name="Root" type="Root">
    <xs:key name="InvalidKey">
    <xs:selector xpath="A[@type="AExtended"]"/>
    <xs:field xpath="@key"/>
    </xs:key>
    <xs:keyref name="InvalidKeyref" refer="InvalidKey">
    <xs:selector xpath="B/Ref_to_AExtended"/>
    <xs:field xpath="."/>
    </xs:keyref>
    </xs:element>
    peterpeter, Feb 12, 2007
    #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. J E E
    Replies:
    0
    Views:
    377
    J E E
    Nov 7, 2003
  2. peterpeter
    Replies:
    0
    Views:
    927
    peterpeter
    Feb 11, 2004
  3. John Carron
    Replies:
    0
    Views:
    471
    John Carron
    Sep 1, 2005
  4. Stanimir Stamenkov
    Replies:
    2
    Views:
    743
    Stanimir Stamenkov
    Oct 25, 2005
  5. Robert Mark Bram
    Replies:
    0
    Views:
    682
    Robert Mark Bram
    Feb 4, 2007
Loading...

Share This Page