Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries [Thread Prev] >Thread Next - Re: How do you best express references to keys/ID's in an XSD ? How do you best express references to keys/ID's in an XSD ?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 | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
