W3C home > Mailing lists > Public > xmlschema-dev@w3.org > September 2006

Re: XML schema for ordinal/nominal variables

From: <noah_mendelsohn@us.ibm.com>
Date: Mon, 4 Sep 2006 15:48:57 -0400
To: "Christian Setzkorn" <christian@setzkorn.eu>
Cc: xmlschema-dev@w3.org
Message-ID: <OFD0AF5CA4.76938FD6-ON852571DF.006C195B-852571DF.006CDBB7@lotus.com>

I think the first question is, what do you want your XML instances to look 
like.  The example type you've given:

<xs:element name = "gender" >
                                 <xs:restriction base = "xs:string" >
                                                 <xs:pattern value "0 
female | 1 male" />

will validate elements like:

<bob>1 male<bob>
<mary>0 female</mary>

in which both the ordinal code and its mapped value appear in the instance 
(though I think you're missing some quotes on the strings in the pattern, 
I  believe your intent is clear. 

Keep in mind that the main purpose of XML Schema is typically to describe 
what your documents will look like.  Schema does have a place to put other 
useful information associated with a declaration called <xsd:appinfo>. 
Perhaps what you want is an enumeration with appinfos, an example of which 
is in the specification itself at [1].  Adapting that to your example:

<simpleType name='gender'>
        <documentation>Used to distinguish boys from girls</documentation>
    <restriction base='integer'>
      <enumeration value='0'>
      <enumeration value='1'>

Now the instances you'll validate will look like:


which I suspect is what you want.  Certain schema validators will make it 
easy for you to use their APIs to navigate to the appinfos at runtime, 
should you wish to have your programs automatically discover the 
associations between the enumeration values and their interpretations as 
genders.  I hope this helps.  Note, however, that enumerations work on 
what schemas call 'values', so 


will also be accepted if the base type is integer.  If you prefer you can 
make the basetype string, in which case only the exact character string 
you put into the enumeration will match, I.e. '0' or '1' respectively.

I hope this is helpful.


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

Noah Mendelsohn 
IBM Corporation
One Rogers Street
Cambridge, MA 02142

"Christian Setzkorn" <christian@setzkorn.eu>
Sent by: xmlschema-dev-request@w3.org
09/04/2006 06:54 AM
        To:     <xmlschema-dev@w3.org>
        cc:     (bcc: Noah Mendelsohn/Cambridge/IBM)
        Subject:        XML schema for ordinal/nominal variables

Dear all,

I would like to define nominal/ordinal variables as XML schema. Both types
of variables are characterized by code/string pairs. Here code is a real

Example of the nominal variable Gender:


Example of the ordinal variable Agreement:

0/strongly disagree
3/strongly agree

My first attempt to define 'Gender' is this:

<xs:element name = "gender" >
                                 <xs:restriction base = "xs:string" >
                                                 <xs:pattern value "0 
female | 1 male" />

Could this be improved?

Any feedback would be very much appreciated. Many thanks in advance.

Best wishes,
Christian Setzkorn

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.11.7/436 - Release Date: 01/09/2006
Received on Monday, 4 September 2006 19:49:16 UTC

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