Sébastien de Mapias
Usenet Archive
- Joined
- Feb 12, 2008
- Messages
- 33
- Reaction score
- 0
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="traveller-id-ag">
~ <xs:attribute name="traveller-id" type="string20" use="required"/> ~ </xs:attributeGroup> ~ ~ <xs:attributeGroup name="ticket-id-ag"> ~ <xs:attribute name="ticket-id" type="string20" use="required"/> ~ </xs:attributeGroup> ~ ~ <xs:attributeGroup name="segment-id-ag"> ~ <xs:attributeGroup ref="product-id-ag"/> ~ <xs:attributeGroup ref="traveller-id-ag"/> ~ </xs:attributeGroup> ~ ~ <xs:complexType name="traveller"> ~ <xs:attributeGroup ref="traveller-id-ag"/> ~ <xs:attributeGroup ref="modification-info-ag"/> ~ <xs:sequence> ~ <xs:element name="traveller-info" type="traveller-info"/> ~ <xs:element name="remark" type="remark" minOccurs=... /> ~ <xs:element name="message" type="message" minOccurs=... /> ~ </xs:sequence> ~ </xs:complexType> ~ ~ <xs:complexType name="segment"> ~ <xs:attributeGroup ref="segment-id-ag"/> ~ <xs:sequence> ~ <xs:element name="segment-info" type="segment-info"/> ~ <xs:element name="price" type="price" minOccurs="0"/> ~ <xs:element name="ticket-ref" minOccurs="0"> ~ <xs:complexType> ~ <xs:attributeGroup ref="ticket-id-ag"/> ~ </xs:complexType> ~ </xs:element> ~ <xs:element name="duration" type="duration" minOccurs=... /> ~ <xs:element name="length" type="length" minOccurs=... /> ~ </xs:sequence> ~ </xs:complexType> ~ ~ <xs:complexType name="ticket"> ~ <xs:attributeGroup ref="ticket-id-ag"/> ~ <xs:sequence> ~ <xs:element name="price" type="price" minOccurs="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="segment">
~ <xs:key name="segment-id"/>
~ <xs:sequence>
~ <xs:element name="segment-info" type="segment-info"/> ~ <xs:element name="price" type="price" minOccurs="0"/> ~ <xs:element name="ticket-ref" minOccurs="0"> ~ <xs:keyref name="ticket-id-ref" ref="ticket-id"/> ~ </xs:element> ~ </xs:sequence> ~ </xs:complexType> ~ ~ <xs:complexType name="ticket"> ~ <xs:key name="ticket-id"/> ~ <xs:sequence> ~ <xs:element name="price" type="price" minOccurs="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="ticket-ref" ref="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ébastien Rigaud
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="traveller-id-ag">
~ <xs:attribute name="traveller-id" type="string20" use="required"/> ~ </xs:attributeGroup> ~ ~ <xs:attributeGroup name="ticket-id-ag"> ~ <xs:attribute name="ticket-id" type="string20" use="required"/> ~ </xs:attributeGroup> ~ ~ <xs:attributeGroup name="segment-id-ag"> ~ <xs:attributeGroup ref="product-id-ag"/> ~ <xs:attributeGroup ref="traveller-id-ag"/> ~ </xs:attributeGroup> ~ ~ <xs:complexType name="traveller"> ~ <xs:attributeGroup ref="traveller-id-ag"/> ~ <xs:attributeGroup ref="modification-info-ag"/> ~ <xs:sequence> ~ <xs:element name="traveller-info" type="traveller-info"/> ~ <xs:element name="remark" type="remark" minOccurs=... /> ~ <xs:element name="message" type="message" minOccurs=... /> ~ </xs:sequence> ~ </xs:complexType> ~ ~ <xs:complexType name="segment"> ~ <xs:attributeGroup ref="segment-id-ag"/> ~ <xs:sequence> ~ <xs:element name="segment-info" type="segment-info"/> ~ <xs:element name="price" type="price" minOccurs="0"/> ~ <xs:element name="ticket-ref" minOccurs="0"> ~ <xs:complexType> ~ <xs:attributeGroup ref="ticket-id-ag"/> ~ </xs:complexType> ~ </xs:element> ~ <xs:element name="duration" type="duration" minOccurs=... /> ~ <xs:element name="length" type="length" minOccurs=... /> ~ </xs:sequence> ~ </xs:complexType> ~ ~ <xs:complexType name="ticket"> ~ <xs:attributeGroup ref="ticket-id-ag"/> ~ <xs:sequence> ~ <xs:element name="price" type="price" minOccurs="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="segment">
~ <xs:key name="segment-id"/>
~ <xs:sequence>
~ <xs:element name="segment-info" type="segment-info"/> ~ <xs:element name="price" type="price" minOccurs="0"/> ~ <xs:element name="ticket-ref" minOccurs="0"> ~ <xs:keyref name="ticket-id-ref" ref="ticket-id"/> ~ </xs:element> ~ </xs:sequence> ~ </xs:complexType> ~ ~ <xs:complexType name="ticket"> ~ <xs:key name="ticket-id"/> ~ <xs:sequence> ~ <xs:element name="price" type="price" minOccurs="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="ticket-ref" ref="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ébastien Rigaud