- From: Christian Setzkorn <christian@setzkorn.eu>
- Date: Tue, 5 Sep 2006 17:35:11 +0100
- To: <noah_mendelsohn@us.ibm.com>
- Cc: <xmlschema-dev@w3.org>
Dear Noah, Many thanks for this. It is exactly what I want. I would like to store the code ('1') but also keep track of what the code means ('male'). I am using ASP.NET/C#. Hence, I could later replace the 'coding' with the 'meaning' if the user prefers this. Thanks again, Chris PS: I didn't really understand why you use <bob></bob> instead of <gender></gender> ... later I would like to use this simple type in complex types with complex content model. > -----Original Message----- > From: xmlschema-dev-request@w3.org [mailto:xmlschema-dev-request@w3.org] > On Behalf Of noah_mendelsohn@us.ibm.com > Sent: 04 September 2006 20:49 > To: Christian Setzkorn > Cc: xmlschema-dev@w3.org > Subject: Re: XML schema for ordinal/nominal variables > > > 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@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 > 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 > > > > > > > > -- > No virus found in this incoming message. > Checked by AVG Free Edition. > Version: 7.1.394 / Virus Database: 268.11.7/436 - Release Date: 01/09/2006 > -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.394 / Virus Database: 268.11.7/436 - Release Date: 01/09/2006
Received on Tuesday, 5 September 2006 16:35:26 UTC