equality and identity of lists in XML Schema

Dear Stefan Wachter,

A long time ago (15 November 2002, to be precise) you asked a question
on the xmlschema-dev list about the definition of list equality.

http://lists.w3.org/Archives/Public/xmlschema-dev/2002Nov/0066.html

This was tracked as an issue against XML Schema 1.0, and then 1.1; the
current record of the issue is as bug 2046 in the W3C's public
instance of Bugzilla, at
http://www.w3.org/Bugs/Public/show_bug.cgi?id=2046

Embarrassing though it is for a bug report to remain unresolved for so
long, I am pleased to be able to say that today the XML Schema WG
adopted a proposal for XSD 1.1 that we believe resolves the issue and
answers the questions you asked in the email of November 2002.

The proposal we adopted today inserts (among other things) the
following text into the discussion of lists in the Datatypes spec:

     Given a list A and a list B, A and B are the same list if they are
     the same sequence of atomic values. The necessary and sufficient
     conditions for this identity are that A and B have the same length
     and that the items of A are pairwise identical to the items of B.

         Note: It is a consequence of the rule just given for list
         identity that there is only one empty list. An empty list
         declared as having ·item type· decimal and an empty list
         declared as having ·item type· string are not only equal but
         identical.

Also

     Two lists A and B are equal if and only if they have the same
     length and their items are pairwise equal. A list of length one
     containing a value V1 and an atomic value V2 are equal if and only
     if V1 is equal to V2.

You asked:

 > When a list valued element or attribute is used as a key then the
 > equality of the values is important. In the following example there
 > are 3 lists with item types "Name", "double", "nameOrDouble":

 > <simpleType name="l1">
 >   <list itemType="Name"/>
 > </simpleType>

 > <simpleType name="l2">
 >   <list itemType="double"/>
 > </simpleType>

 > <simpleType name="l3">
 >   <list itemType="tns:nameOrDouble"/>
 > </simpleType>

 > <simpleType name="nameOrDouble">
 >   <union memberTypes="Name double"/>
 > </simpleType>

 > Are these lists equal?

 > 1. Items types of lists are different but item types of items are
 > equal: <element xsi:type="l1">1.0 2.0</element> = <element
 > xsi:type="l3">1.0 2.0</element>

 > 2. Item types of lists are different but there are no items.
 > <element xsi:type="l1"/> = <element xsi:type="l2"/>

 > What are the exact rules for comparing lists? Thanks for your
 > attention,


We believe that the text inserted today allows your questions to
be answered:

   1 If the two lists are declared with different item types, but
     the items of the two lists are the same values (which means
     the item types of the two lists must have overlapping value
     spaces, if the lists are non-empty), then the two lists are
     the same list.  It is values, not strings, that are compared.

     In your example, whether

           <element xsi:type="l1">1.0 2.0</element>
         = <element xsi:type="l3">1.0 2.0</element>

     or not depends on whether you really meant "l1" instead of
     "l2" in the first list, and if you really meant "l1", then
     what type Name is.

     Assuming that Name is a typo or shorthand for NCName, then
     <element xsi:type="l1">1.0 2.0</element> is invalid since "1.0"
     and "2.0" are not in the lexical space of NCName.  But since they
     ARE in the lexical space of double, it is quite true that

           <element xsi:type="l2">1.0 2.0</element>
         = <element xsi:type="l3">1.0 2.0</element>

   2 If lists A and B are each empty (have no items), then A and
     B are the same list.

We appreciate your comment, which raised an important point, and we
apologize for the length of time it has taken to resolve it.

If you still have any interest in XML Schema, we would be interested
to hear from you whether the proposal adopted by the Working Group
resolves the issue to your satisfaction, or whether it is for
some reason (other than the passage of time!) unsatisfactory.

best regards,

C. M. Sperberg-McQueen
World Wide Web Consortium, MIT/CSAIL

Received on Saturday, 31 May 2008 02:40:55 UTC