Re: IDREFS types in schemas

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 
DTD."

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.

Noah

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

--------------------------------------
Noah Mendelsohn 
IBM Corporation
One Rogers Street
Cambridge, MA 02142
1-617-693-4036
--------------------------------------






        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:

QUOTE

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 
DTD.
Specifically they should NEVER be used together with key/keyref as
this will create total confusion, because now you have two separate 
mechanisms
trying to do the same thing mixed together with weird
consequences.

UNQUOTE

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

Regards,
Hans

==================================

"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 
Edinburgh
>                       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