• Post Reply Bookmark Topic Watch Topic
  • New Topic

XML Schema "key" and "keyref" help  RSS feed

 
Chris Bilinski
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I don't know why reference between an attribute and an element doesn't work. Maybe you can tell me, whether there is something wrong with this code or this is just one of schema constraints.
Here you have a part of schema:
<xsd:key name="keyExampl">
<xsd:selector xpath="...path.../example_key"/>
<xsd:field xpath="@id"/> <!-- Note, that "id" is an attribute. -->
</xsd:key>
<xsd:keyref name="ref_example" refer="keyExampl">
<xsd:selector xpath="...path.../example_ref"/>
<xsd:field xpath="id_ex"/> <!-- Note, that "id_ex" is an element. -->
</xsd:keyref>
and here goes sample xml:
<example_key id="1">
<element1>...</element1>
<element2>...</element2>
...
<example_key>
<example_ref>
<id_ex>1</id_ex>
<element1>...</element1>
<element2>...</element2>
...
<example_ref>
it seems, that if I make id_ex an attribute (not the element) then the reference works perfectly. Could you help me with it.
The reason, why I'm asking about it is that I want to make many references from one node. Something like:
<example_ref>
<id_ex>1</id_ex>
<id_ex>2</id_ex>
<id_ex>3</id_ex>
...
<element1>...</element1>
<element2>...</element2>
...
<example_ref>
Thanks,
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!