Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XML schema for ordinal/nominal variables

From: noah_mendelsohn@--.---.---
To: "Christian Setzkorn" <christian@--------.-->
Date: 9/4/2006 11:49:00 AM
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:simpleType>
                                 <xs:restriction base = "xs:string" >
                                                 <xs:pattern value "0 
female | 1 male" />
                                 </xs:restriction>
                 </xs:simpleType>
</xs:element>

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'>
    <annotation>
        <documentation>Used to distinguish boys from girls</documentation>
    </annotation>
    <restriction base='integer'>
      <enumeration value='0'>
        <annotation>
            <documentation>Female</documentation>
        </annotation>
      </enumeration>
      <enumeration value='1'>
        <annotation>
            <documentation>Male</documentation>
        </annotation>
      </enumeration>
    </restriction>
</simpleType>

Now the instances you'll validate will look like:

<bob>1</bob>
<mary>0</mary>

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 

<bob>0001</bob>

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.

Noah

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

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








"Christian Setzkorn" <christian@s...>
Sent by: xmlschema-dev-request@w...
09/04/2006 06:54 AM
 
        To:     <xmlschema-dev@w...>
        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
number.

Example of the nominal variable Gender:

code/string
#######
1/male
0/female

Example of the ordinal variable Agreement:

code/string 
#######
0/strongly disagree
1/disagree
2/agree
3/strongly agree

My first attempt to define 'Gender' is this:

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

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
 






From christian@s... Tue Sep 05 16:35:26 2006
Received: from lisa.w3.org ([128.30.52.41])
	by frink.w3.org with esmtp (Exim 4.50)
	id 1GKdtW-0001Kt-Bg
	for xmlschema-dev@l...;


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent