W3C home > Mailing lists > Public > xmlschema-dev@w3.org > December 2003

Re: IDREFS types in schemas

From: <noah_mendelsohn@us.ibm.com>
Date: Wed, 24 Dec 2003 19:00:04 -0500
To: Hans Teijgeler <hans.teijgeler@quicknet.nl>
Cc: "Henry S. Thompson" <ht@cogsci.ed.ac.uk>, Morgane Erenati <morgane.erenati@wanadoo.fr>, xmlschema-dev@w3.org
Message-ID: <OFD9F25ABF.9A55B1D5-ON85256E06.008258BF@lotus.com>

Let me take a crack at answering, though neither Henry or I speak 
officially for the schema workgroup in this case.

>> What is the official party line?

The Schema Recommendation says both features are there, neither is 
deprecated, and you are welcome to use either or both.   The correct 
validation behavior is as specified in the Recommendation, and if that 
proves in any way ambiguous, you should file a bug report.  I think it's 
straightforward:  all the constraints you declare must be met for the 
instance to be considered valid. 

The only warning I see is at [1] where it says:

"For compatibility (see Terminology (1.4)) this datatype should be used 
only on attributes"

You quote the Altova help desk as saying:

"ID/IDREF datatypes are  present in XML Schema only for compatibility 
reasons with respect to DTDs. They should NOT be used under normal 
circumstances, except when the goal is to model behavior of an existing 

I don't quite agree.  They are there to provide a facility similar to that 
available in DTDs, and you should use them whenever they are the best 
model to meet your needs.  If a facility is to be avoided the 
Recommendation would say so, and in this case it doesn't.

Note that ID/IDREF are structurally different than key/keyref.  The former 
are types:  you can't have an attribute which is simultaneously typed as 
an integer and an ID.  On the other hand, a given attribute or element can 
participate is a key or keyref in many relationships simultaneously, and 
indeed both elements and attributes are supported.  You may or may not 
feel in certain circumstances that typing an attribute as an IDREF more 
directly models your intentions.  It's fairly common to see this done in 
situations where graphs are being encoded into XML, as being a reference 
is inherent in the nature of an attribute representing a graph edge.  Such 
usage is not in general limited to cases where there was a pre-existing 
DTD.  It's just a matter of taste.  It certainly is true that for many 
purposes key/keyref is more powerful and appropriate. 

It is also true that I don't thing the Schema WG paid great attention to 
the convenience of using the two to constrain the same data at the same 
time.   So, if it proves inconvenient or confusing to do so, don't.  On 
the other hand, I think the recommendation is fairly clear that you can 
use both sets of constraint mechanisms separately or together, and all 
declared constraints must be met for the document to be valid.

By the way, there has been a simmering debate in the W3C about a range off 
issues relating to mechanisms of this sort.  I can't easily reproduce it 
here, but a search of the TAG mailing list archives should turn it up if 
you're interested.  I hope this helps.


[1] http://www.w3.org/TR/xmlschema-2/#IDREF

Noah Mendelsohn 
IBM Corporation
One Rogers Street
Cambridge, MA 02142

        Hans Teijgeler <hans.teijgeler@quicknet.nl>
        Sent by: xmlschema-dev-request@w3.org
        12/24/03 05:11 PM
                 To: "Henry S. Thompson" <ht@cogsci.ed.ac.uk>
                 cc: Morgane Erenati <morgane.erenati@wanadoo.fr>, 
xmlschema-dev@w3.org, (bcc: Noah Mendelsohn/Cambridge/IBM)
                 Subject: Re: IDREFS types in schemas

Dear Henry,

On Dec. 4th 2002 a person of the Altova (=Spy) helpdesk wrote me:


ID/IDREF datatypes are  present in XML Schema only for compatibility 
reasons with
respect to DTDs. They should NOT be used under normal
circumstances, except when the goal is to model behavior of an existing 
Specifically they should NEVER be used together with key/keyref as
this will create total confusion, because now you have two separate 
trying to do the same thing mixed together with weird


I do not sense that from your reply below. What is the official party 



"Henry S. Thompson" wrote:

> xs:ID (I think that's what you want for inp), xs:IDREF and xs:IDREFS
> function the same as they do in DTDs -- see any introductory XML book
> for details.
> Something like
> <xs:element name="GInP">
>  <xs:complexType>
>   <xs:sequence>
>    . . .
>   </xs:sequence>
>   <xs:attribute name="inp" type="xs:ID" use="required"/>
>  </xs:complexType>
> </xs:element>
> <xs:element name="Correspondance">
>  <xs:complexType>
>   <xs:sequence>
>    . . .
>   </xs:sequence>
>   <xs:attribute name="corresplist" type="xs:IDREFS"/>
>  </xs:complexType>
> </xs:element>
> or maybe I have the attributes on the wrong elements, I wasn't sure
> from your description.
> See the Primer [1] for an overall introduction to elements and types,
> and also the more powerful schema-native key and keyref.
> ht
> [1] http://www.w3.org/TR/xmlschema-0/
> --
>   Henry S. Thompson, HCRC Language Technology Group, University of 
>                       Half-time member of W3C Team
>      2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
>             Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
>                      URL: http://www.ltg.ed.ac.uk/~ht/
>  [mail really from me _always_ has this .sig -- mail without it is 
forged spam]
Received on Wednesday, 24 December 2003 19:05:38 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:56:04 UTC