Altova Mailing List Archives


How do you best express references to keys/ID's in an XSD ?

From: =?ISO-8859-1?Q?S=E9bastien_de_Mapias?= <sglrigaud@-----.--->
To: NULL
Date: 10/1/2008 1:59:00 AM
Good day,
To people well acquainted with XML schemas manipulation here,
how do you express relationships/references between elements ?

Take the following excerpt from one of the analysts around me:

~ <xs:attributeGroup name=3D"traveller-id-ag">
~   <xs:attribute name=3D"traveller-id" type=3D"string20" use=3D"required"/=
>
~ </xs:attributeGroup>
~
~ <xs:attributeGroup name=3D"ticket-id-ag">
~   <xs:attribute name=3D"ticket-id" type=3D"string20" use=3D"required"/>
~ </xs:attributeGroup>
~
~ <xs:attributeGroup name=3D"segment-id-ag">
~   <xs:attributeGroup ref=3D"product-id-ag"/>
~   <xs:attributeGroup ref=3D"traveller-id-ag"/>
~ </xs:attributeGroup>
~
~ <xs:complexType name=3D"traveller">
~   <xs:attributeGroup ref=3D"traveller-id-ag"/>
~   <xs:attributeGroup ref=3D"modification-info-ag"/>
~   <xs:sequence>
~     <xs:element name=3D"traveller-info" type=3D"traveller-info"/>
~     <xs:element name=3D"remark" type=3D"remark" minOccurs=3D... />
~     <xs:element name=3D"message" type=3D"message" minOccurs=3D... />
~   </xs:sequence>
~ </xs:complexType>
~
~ <xs:complexType name=3D"segment">
~   <xs:attributeGroup ref=3D"segment-id-ag"/>
~   <xs:sequence>
~     <xs:element name=3D"segment-info" type=3D"segment-info"/>
~     <xs:element name=3D"price" type=3D"price" minOccurs=3D"0"/>
~     <xs:element name=3D"ticket-ref" minOccurs=3D"0">
~       <xs:complexType>
~         <xs:attributeGroup ref=3D"ticket-id-ag"/>
~       </xs:complexType>
~     </xs:element>
~     <xs:element name=3D"duration" type=3D"duration" minOccurs=3D... />
~     <xs:element name=3D"length" type=3D"length" minOccurs=3D... />
~   </xs:sequence>
~ </xs:complexType>
~
~ <xs:complexType name=3D"ticket">
~   <xs:attributeGroup ref=3D"ticket-id-ag"/>
~   <xs:sequence>
~     <xs:element name=3D"price" type=3D"price" minOccurs=3D"0">
~     </xs:element>
~     [...]
~   </xs:sequence>
~ </xs:complexType>

You see the guy has first declared attribute groups to specify
ID's (simple or composite), that he later uses inside complex
types as real ID's/keys or as references either (which kind of
annoys me): in the complex type "ticket", the "ticket-id-ag"
is a *key*, a string that identifies uniquely a ticket; but
in "segment", it's a reference to the ticket defined below
(but to express the "ref" difference we have, he's put this
"ticket-id-ag" inside an element named "ticket-ref")...

Shouldn't it be more clear-cut and legible to do something
like (and get rid of these attribute groups as well maybe ?):
~ <xs:complexType name=3D"segment">
~   <xs:key name=3D"segment-id"/>
~   <xs:sequence>
~     <xs:element name=3D"segment-info" type=3D"segment-info"/>
~     <xs:element name=3D"price" type=3D"price" minOccurs=3D"0"/>
~     <xs:element name=3D"ticket-ref" minOccurs=3D"0">
~         <xs:keyref name=3D"ticket-id-ref" ref=3D"ticket-id"/>
~     </xs:element>
~   </xs:sequence>
~ </xs:complexType>
~
~ <xs:complexType name=3D"ticket">
~   <xs:key name=3D"ticket-id"/>
~   <xs:sequence>
~     <xs:element name=3D"price" type=3D"price" minOccurs=3D"0">
~     </xs:element>
~     [...]
~   </xs:sequence>
~ </xs:complexType>

or something similar (I'm not sure at all of the syntax
here, perhaps "segment" could be further simplified with:
~     <xs:keyref name=3D"ticket-ref" ref=3D"ticket-id" >
~     </xs:keyref>
with no xs:element surrounding it ?
I have no idea - sorry I'm not very familiar with XML
schemas...) ?

A detail that might have its importance: this comes from
XSD's used with JAXB to generate classes of our protocol...

Thanks a lot in advance for any help and advice about all
this stuff !
Regards,
S=E9bastien Rigaud

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.