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

J

Joyce

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!
 
S

Stan Kitsis [MSFT]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top