473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

XML Schema enumeration question

I know that I can set up an enumeration as follows ( just typed in quick so
may have syntax errors ):

<xsd:simpleType name="colors">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="red"/>
<xsd:enumeration value="yellow"/>
<xsd:enumeration value="blue"/>
</xsd:simpleType>

However, what I need to do is associate each element of the "colors"
enumeration with an integer as well. For example, a string value of "red"
or an int of 10 should be treated the same:

String int value
red 10
yellow 20
blue 30

Is there any way to assign the int value to the enumeration? Is the "id"
attribute what I should be using? For example:

<xsd:simpleType name="colors">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="red" id="10"/>
<xsd:enumeration value="yellow" id="20"/>
<xsd:enumeration value="blue" id="30"/>
</xsd:simpleType>

Any help would be appreciated!

Thanks,
Justin
Jul 20 '05 #1
1 12597
"Justin Wright" <jw*******@dls.net> wrote:
I know that I can set up an enumeration as follows ( just typed in quick so
may have syntax errors ):

<xsd:simpleType name="colors">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="red"/>
<xsd:enumeration value="yellow"/>
<xsd:enumeration value="blue"/>
</xsd:restriction>
</xsd:simpleType>

However, what I need to do is associate each element of the "colors"
enumeration with an integer as well. For example, a string value of "red"
or an int of 10 should be treated the same:

String int value
red 10
yellow 20
blue 30
because the "colors" simple type is a restriction of xsd:string, you
can define the values of the enumerations like:

<xsd:enumeration value="red:10"/>
Is there any way to assign the int value to the enumeration? Is the "id"
attribute what I should be using? For example:

<xsd:simpleType name="colors">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="red" id="10"/>
<xsd:enumeration value="yellow" id="20"/>
<xsd:enumeration value="blue" id="30"/>
</xsd:restriction>
</xsd:simpleType>


No, the value of the id attribute must match a NCName production
(http://www.w3.org/TR/xmlschema-2/#ID), i.e., it must start with
either a letter or an underscore.

You may define a colormap and use xsd:key/xsd:keyref/xsd:unique:

<xsd:simpleType name="colorname">
<xsd:restriction base="xsd:string>
<xsd:enumeration value="red"/>
<xsd:enumeration value="yellow"/>
<xsd:enumeration value="blue"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:element name="color">
<xsd:complexType>
<xsd:attribute name="name" type="colorname"/>
<xsd:attribute name="value">
<xsd:simpleType>
<xsd:restriction base="xsd:int>
<xsd:enumeration value="10"/>
<xsd:enumeration value="20"/>
<xsd:enumeration value="30"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
</xsd:element>

<xsd:element name="colormap">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="color" maxOccurs="unbounded"/>
</xsd:sequence
</xsd:complexType>

<!-- make sure that color values and names are unique -->
<xsd:unique name="color-value">
<xsd:selector xpath="color"/>
<xsd:field xpath="@value"/>
</xsd:unique>
<xsd:unique name="color-name">
<xsd:selector xpath="color"/>
<xsd:field xpath="@name"/>
</xsd:unique>
<xsd:key name="colormap">
<xsd:selector xpath="color"/>
<xsd:field xpath="@name"/>
<xsd:field xpath="@value"/>
</xsd:key>
</xsd:element>

<xsd:element name="wrapper">
....
<xsd:element ref="colormap"/>
....
<xsd:element ref="item-using-colors"/>
....
<xsd:keyref name="color-used" refer="color-name">
<xsd:selector xpath="item-using-colors"/>
<xsd:field xpath="@color"/>
</xsd:keyref>
</xsd:element>

Cheers

Jens
--
(Intentionally left blank.)
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: C. M. Sperberg-McQueen | last post by:
wooks (wookiz@hotmail.com) wrote: > <?xml version='1.0'?> > <userlogin xmlns="urn:faster:userlogin" > xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> > <login>mick</login> > ...
0
by: Antony | last post by:
Hi there, firstly thank you for thinking about this problem of mine. This is a long message because I want to put all the facts (the XML and the schema) to try to get a solution from you helpful...
1
by: Fred Smith | last post by:
Any suggestions or tips to the questions below I have been wrestling with would be most welcome: I have an example XSD file I have been experimenting with. Suppose a user can select from 1 to 4...
2
by: M Rao | last post by:
I have xml data coming in as a stream from a web service running against exchange server.The attributes for the elements dtstart and dtend, b:dt="dateTime.tz"...
1
by: Jeff S | last post by:
Hello all, I'm trying to design a schema from which I can generate a typed dataset class. I'm having problems incorporating choice and enumerations in the schema and getting the xml results...
0
by: c j anderson, mcp | last post by:
Core Question: Is there a better way to dynamically pull the allowed values of an attribute out of a dataset's schema. I have an XML file that contains a string element with two attributes,...
4
by: Stan R. | last post by:
Hello, I have xmllint and xsltproc installed and running on both my linux and win32 platforms, all seems good. I have a couple questions though. 1) If I have an external dtd file, which is...
5
by: hello | last post by:
How can I define the schema so that myage element has to be double or null? <xs:simpleType name="myage"> <xs:restriction base="xs:double"> <xs:enumeration value="null"/> </xs:restriction>...
0
by: SkyScrap | last post by:
Hi, my problem is the following. I have a complex type that has one attribute that is based on an enumeration. The XML schema that I define is fixed, but a customer/user of that schema should be...
1
by: brucepickford001 | last post by:
Hi, I have a not simple problem. I want the following XML to be schema valid <PopulationDemographic> <PersonName>Joe Blogs</PersonName> <Age>2</Age> <Category>baby</Category>...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.