Re: doubt on keyref

Hi,

nandanprasad <pola_nandana@emc.com> writes:

> Here is a skeleton of xml, Can we have a keyref element refering to key of
> some other element?  In the  samples I f find  that the keyref element
> normally points to key element defined within the same context eleement.
>
>
> <element name="A">
> <xs:key name="key1"/>
> </element>
>
> <element name="B">
> <xs:keyref name="key2" refer="key1"/>
> </element>

xs:keyref should refer to the xs:key defined in the same element or
in one of its ancestors. It is best however to keep both key and
keyref at the same, closest common level. For example, if you
had a third element which contains A and B then it would be a
good idea to put key and keyref there:

<element name="C">
  <complexType>
    <sequence>
      <element ref="A"/>
      <element ref="B"/>
    </sequence>
  </complexType>

  <key name="a-key">
    <selector xpath="A"/>
    <field xpath="@key"/>
  </key>

  <keyref name="a-ref" refer="a-key">
    <selector xpath="B"/>
    <field xpath="@ref"/>
  </keyref>
</element>

Here I assume that element A has a key attribute "key" and element B
has a reference attribute "ref".

hth,
-boris


-- 
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis.com
Open-Source, Cross-Platform C++ XML Data Binding

Received on Friday, 23 February 2007 20:45:48 UTC