RE: How to get enumeration values in alphabetical order

Swayam Vemuri writes:

> The enumerations, the values are not in alphabetical order, I 
> thought they appear
> As it is when I instantiate the schema Or it will come in sorted order ?

I'm afraid I'm not quite understanding what you mean, but I wonder whether 
you are misunderstanding what enumerations are for.  Have you by any 
chance looked at the discussion of enumerations in the XML Schema Primer 
[1]?

<xsd:simpleType name="USState">
  <xsd:restriction base="xsd:string">
    <xsd:enumeration value="AK"/>
    <xsd:enumeration value="AL"/>
    <xsd:enumeration value="AR"/>
    <!-- and so on ... -->
  </xsd:restriction>
</xsd:simpleType>

If you then have an element declaration of that type:

<xsd:element name="myState" type="USState>

Then your XML document will validate if it has a single element like this:

<myState>AL</myState>

Alphabetical order is not an issue.  In the original declaration, you can 
list the enumeration in any order you like, but the specification makes 
clear that what you get is a set, not an ordered list, so this would be 
the exact same type:

<xsd:simpleType name="USState">
  <xsd:restriction base="xsd:string">
    <xsd:enumeration value="AR"/>
    <xsd:enumeration value="AL"/>
    <xsd:enumeration value="AK"/>
  </xsd:restriction>
</xsd:simpleType>

Quoting from the Recommentation [2]:

"[Definition:]   enumeration constrains the ·value space· to a specified 
set of values.

enumeration does not impose an order relation on the ·value space· it 
creates; the value of the ·ordered· property of the ·derived· datatype 
remains that of the datatype from which it is ·derived·. "

So, no order of either the values recorded in the schema, or of the value 
space of the type (I.e. of the contents of elements or attributes 
validated by the type) is implied.

Noah

[1] http://www.w3.org/TR/xmlschema-0/#CreatDt

[2] http://www.w3.org/TR/2004/PER-xmlschema-2-20040318/#dt-enumeration


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








"Swayam Vemuri -X \(swvemuri - WIPRO at Cisco\)" <swvemuri@cisco.com>
Sent by: xmlschema-dev-request@w3.org
03/13/2007 09:55 AM
 
        To:     <noah_mendelsohn@us.ibm.com>, "Michael Kay" 
<mike@saxonica.com>
        cc:     <xmlschema-dev@w3.org>, <xmlschema-dev-request@w3.org>
        Subject:        RE: How to get enumeration values in alphabetical 
order


Oh! That’s an interesting piece of info.
Thanks a lot Noah and Mike for your responses.
 
Well What I was looking for is if I write a schema wherein while writing
The enumerations, the values are not in alphabetical order, I thought they 
appear
As it is when I instantiate the schema Or it will come in sorted order ?
 
 
Thanks,
Swayam
 

From: noah_mendelsohn@us.ibm.com [mailto:noah_mendelsohn@us.ibm.com] 
Sent: Tuesday, March 13, 2007 7:19 PM
To: Swayam Vemuri -X (swvemuri - WIPRO at Cisco)
Cc: xmlschema-dev@w3.org; xmlschema-dev-request@w3.org
Subject: Re: How to get enumeration values in alphabetical order
 

I'm not sure what you mean by "getting" enumeration values.  If you want 
to do something like extract them from the schema itself, well schema 
documents are themselves XML documents, so you could run a stylesheet over 
your schema document.  Are you looking for something like: 

        <element name="container"> 
         <sequence> 
                <element ref="e" type="someEnumeration" maxOccurs="*"/> 
         </sequence> 
        </element 
  

and to insist that the values of e occur alphabetically.  The answer in 
Schema 1.0 is no, can't do it.  In schema 1.1, the new "Assertions" 
facility would let you put an XPath assertion on the container.  If your 
processor supported a sufficiently broad subset of the XPath language, and 
if your definition of "alphatbetical order" involves a string comparision 
that XPath can easily do, then yes, I think you could enforce that in XML 
Schema 1.1. 

Noah 

[1] http://www.w3.org/TR/xmlschema11-1/#cAssertions 

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






 
"Swayam Vemuri -X \(swvemuri - WIPRO at Cisco\)" <swvemuri@cisco.com> 
Sent by: xmlschema-dev-request@w3.org 
03/13/2007 09:26 AM 
        
        To:        <xmlschema-dev@w3.org> 
        cc:        (bcc: Noah Mendelsohn/Cambridge/IBM) 
        Subject:        How to get enumeration values in alphabetical 
order



Hi, 
  
How to get enumeration values in alphabetical order. 
Is there any way, pl let me know 
  
Thanks 
Swayam 

Received on Tuesday, 13 March 2007 14:40:42 UTC