468,720 Members | 1,737 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,720 developers. It's quick & easy.

XML Schema - How to do a key-value map with 2 enumerations?

In my schema I have 2 enumerations, let's say, country description and
country code, and I want to use them so I can map each country
description to its precise country code (and no other).
So far I've seen I can define both keys for description and code, but
my XMLs validate even if I choose a wrong pair:

Here are my both enumerations (abbreviated)
<xs:simpleType name="COUNTRYCODE">
<xs:restriction base="xs:int">
<xs:enumeration value="4"/>
<xs:enumeration value="8"/>
<xs:enumeration value="958"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="COUNTRYDESC">
<xs:restriction base="xs:string">
<xs:maxLength value="40"/>
<xs:enumeration value="Afghanistan"/>
<xs:enumeration value="Albania"/>
<xs:enumeration value="Germany"/>
</xs:restriction>
</xs:simpleType>

And I use the "country" element as follows:

<xs:element name="COUNTRY">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="COUNTRYDESC"/>
<xs:element name="value" type="COUNTRYCODE"/>
</xs:sequence>
</xs:complexType>
</xs:element>

How should I define the map and the keys, etc. so that something like
this validates:

<COUNTRY>
<COUNTRYDESC>Germany</COUNTRYDESC>
<COUNTRYCODE>958</COUNTRYCODE>
</COUNTRY>

But this DOES NOT validate (as it's a wrong description-code pair):

<COUNTRY>
<COUNTRYDESC>Afghanistan</COUNTRYDESC>
<COUNTRYCODE>958</COUNTRYCODE>
</COUNTRY>

I'll be very grateful for any help!
Jul 20 '05 #1
1 3778
Hi Joyce,

You can't specify this restriction in XML Schema. Have you considered doing
it this way:

<xs:simpleType name="countryDescCode">

<xs:restriction base="xs:string">

<xs:enumeration value="Afghanistan, 4"/>

<xs:enumeration value="Albania, 8" />

<xs:enumeration value="Germany, 958"/>

</xs:restriction>

</xs:simpleType>
--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

"Joyce" <jo*********@gmail.com> wrote in message
news:7b*************************@posting.google.co m...
In my schema I have 2 enumerations, let's say, country description and
country code, and I want to use them so I can map each country
description to its precise country code (and no other).
So far I've seen I can define both keys for description and code, but
my XMLs validate even if I choose a wrong pair:

Here are my both enumerations (abbreviated)
<xs:simpleType name="COUNTRYCODE">
<xs:restriction base="xs:int">
<xs:enumeration value="4"/>
<xs:enumeration value="8"/>
<xs:enumeration value="958"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="COUNTRYDESC">
<xs:restriction base="xs:string">
<xs:maxLength value="40"/>
<xs:enumeration value="Afghanistan"/>
<xs:enumeration value="Albania"/>
<xs:enumeration value="Germany"/>
</xs:restriction>
</xs:simpleType>

And I use the "country" element as follows:

<xs:element name="COUNTRY">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="COUNTRYDESC"/>
<xs:element name="value" type="COUNTRYCODE"/>
</xs:sequence>
</xs:complexType>
</xs:element>

How should I define the map and the keys, etc. so that something like
this validates:

<COUNTRY>
<COUNTRYDESC>Germany</COUNTRYDESC>
<COUNTRYCODE>958</COUNTRYCODE>
</COUNTRY>

But this DOES NOT validate (as it's a wrong description-code pair):

<COUNTRY>
<COUNTRYDESC>Afghanistan</COUNTRYDESC>
<COUNTRYCODE>958</COUNTRYCODE>
</COUNTRY>

I'll be very grateful for any help!

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Olaf Meyer | last post: by
reply views Thread by peterpeter | last post: by
reply views Thread by johnsocs | last post: by
3 posts views Thread by johnsocs | last post: by
4 posts views Thread by Iain A. Mcleod | last post: by
1 post views Thread by Mr. Almenares | last post: by
7 posts views Thread by Robert Stearns | last post: by
6 posts views Thread by Emma Middlebrook | last post: by
1 post views Thread by Oskars | last post: by
9 posts views Thread by bryonone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.