473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
Oct 1 '08 #1
3 1446
Sébastien de Mapias wrote:
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>
You need four definitions, one for the element or attribute which is an
id or key, one for the element or attribute which is an id reference or
key reference, one for defining the key with xs:key, and the last for
defining the key reference with xs:keyref. See
http://www.w3.org/TR/xmlschema-0/#sp...ysAndtheirRefs
--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 1 '08 #2
See http://www.w3.org/TR/xmlschema-0/#sp...ysAndtheirRefs

Thanks for your answer. I'm afraid I still don't understand how key/
references
have to be expressed. In the report.xsd example schema,
1/ I see they use this <selector xpath...tag: DO YOU HAVE TO USE IT
in combination with KEY/KEYREF's tags ?
2/ this way do you easily see the references of 'regions' and 'parts'
to
purchaseReport ?

Thanks.
SR
Oct 1 '08 #3
Sébastien de Mapias wrote:
>See http://www.w3.org/TR/xmlschema-0/#sp...ysAndtheirRefs

Thanks for your answer. I'm afraid I still don't understand how key/
references
have to be expressed. In the report.xsd example schema,
1/ I see they use this <selector xpath...tag: DO YOU HAVE TO USE IT
in combination with KEY/KEYREF's tags ?
Yes, you use selector and field as child elements of key and keyref
elements to precisely define what constitutes the key respectively the
key reference.
2/ this way do you easily see the references of 'regions' and 'parts'
to
purchaseReport ?
In that example the 'number' attribute of 'parts/part' elements inside
the 'purchaseReport' element is a key referenced by the 'number'
attribute of 'regions/zip/part' elements.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 1 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sasha | last post by:
Hi everybody, I would like to hear your thoughts on the following problem. We have the following classes. Class Exam int ID* int Version* string Name
9
by: Sasha | last post by:
Hi, I am extending standard IEnumerator, and I was just wondering what is the best way to make enumarator safe? What do I mean by safe? Detect deletes and all... My idea is to have private Guid...
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
4
by: xenophon | last post by:
I have a class that is used in an ASP.NET app, a WinForms app, and a Win32 Service. What is the best way to tell what environment the code is currently instanced in? Thanks.
2
by: Scott Goodwin | last post by:
In the following example: create table parent ( id integer unique not null, name varchar(24) ); create table child ( first_name varchar(256), last_name varchar(256)
4
by: Andrew Robinson | last post by:
My main dev machine has WinXp and VS2005 (pro). 1. I need to install VWD Express Edition so that I can do some instruction on this. Any issues with both on the same machine. Installation order?...
9
by: Peted | last post by:
Hi Looking for advice on best way to implement this idea I have a form with 10 text boxes, and one button. when user clicks button i want to transmit info in text boxes to a device, but i only...
3
by: Alexander Higgins | last post by:
Hi, I am working on an NNTP Client via windows forms and am actually try to login into this group to no avail. I am sending AUTHINFO USER username <where username=myemail address AUTHINFO...
4
by: K Viltersten | last post by:
We have a project working well today and it's developed on VS2005. Since we're planing to switch to VS2008 in a soon future, i've been trying to move the project to VS2008 Express (Web...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.