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=AExte nded".
I want to have type safety for the reference "Ref_to_AExtend ed" 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_AExtend ed" element of type
"B".
But there's a problem: The XPath expressions in key/keyref do not
allow to contain tests like [@type="AExtende d"]. 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:complexTy pe name="Root">
<xs:sequence>
<xs:element name="A" type="ABase"
minOccurs="0"
maxOccurs="unbo unded"/>
</xs:sequence>
</xs:complexType>
<xs:complexTy pe name="ABase">
<xs:attribute name="key" type="xs:ID" use="required"/
></xs:complexType>
<xs:complexTy pe name="AExtended ">
<xs:complexCont ent>
<xs:extension base="ABase"/>
</xs:complexConte nt>
</xs:complexType>
<xs:complexTy pe name="B">
<xs:sequence>
<xs:element name="Ref_to_AE xtended"
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:noNamespace SchemaLocation= "test.xsd">
<A xsi:type="AExte nded" key="key1"/>
<B>
<Ref_to_AExtend ed>key1</Ref_to_AExtende d>
</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="InvalidKe y">
<xs:selector xpath="A[@type="AExtende d"]"/>
<xs:field xpath="@key"/>
</xs:key>
<xs:keyref name="InvalidKe yref" refer="InvalidK ey">
<xs:selector xpath="B/Ref_to_AExtende d"/>
<xs:field xpath="."/>
</xs:keyref>
</xs:element>