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

Discussion in 'XML' started by Joyce, Feb 14, 2005.

  1. Joyce

    Joyce Guest

    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!
    Joyce, Feb 14, 2005
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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!
    Stan Kitsis [MSFT], Feb 18, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markus
    Replies:
    1
    Views:
    1,522
    Markus
    Nov 23, 2005
  2. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,245
    Stanimir Stamenkov
    Apr 25, 2005
  3. Patrick Guio
    Replies:
    6
    Views:
    3,190
    chris
    Oct 20, 2004
  4. Replies:
    3
    Views:
    2,830
  5. SkyScrap
    Replies:
    0
    Views:
    884
    SkyScrap
    Nov 23, 2006
Loading...

Share This Page