473,791 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:simpleTyp e name="COUNTRYCO DE">
<xs:restricti on base="xs:int">
<xs:enumerati on value="4"/>
<xs:enumerati on value="8"/>
<xs:enumerati on value="958"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleTyp e name="COUNTRYDE SC">
<xs:restricti on base="xs:string ">
<xs:maxLength value="40"/>
<xs:enumerati on value="Afghanis tan"/>
<xs:enumerati on value="Albania"/>
<xs:enumerati on 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="COUNTRYDE SC"/>
<xs:element name="value" type="COUNTRYCO DE"/>
</xs:sequence>
</xs:complexType>
</xs:element>

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

<COUNTRY>
<COUNTRYDESC>Ge rmany</COUNTRYDESC>
<COUNTRYCODE>95 8</COUNTRYCODE>
</COUNTRY>

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

<COUNTRY>
<COUNTRYDESC>Af ghanistan</COUNTRYDESC>
<COUNTRYCODE>95 8</COUNTRYCODE>
</COUNTRY>

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

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

<xs:simpleTyp e name="countryDe scCode">

<xs:restricti on base="xs:string ">

<xs:enumerati on value="Afghanis tan, 4"/>

<xs:enumerati on value="Albania, 8" />

<xs:enumerati on 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*********@gm ail.com> wrote in message
news:7b******** *************** **@posting.goog le.com...
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:simpleTyp e name="COUNTRYCO DE">
<xs:restricti on base="xs:int">
<xs:enumerati on value="4"/>
<xs:enumerati on value="8"/>
<xs:enumerati on value="958"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleTyp e name="COUNTRYDE SC">
<xs:restricti on base="xs:string ">
<xs:maxLength value="40"/>
<xs:enumerati on value="Afghanis tan"/>
<xs:enumerati on value="Albania"/>
<xs:enumerati on 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="COUNTRYDE SC"/>
<xs:element name="value" type="COUNTRYCO DE"/>
</xs:sequence>
</xs:complexType>
</xs:element>

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

<COUNTRY>
<COUNTRYDESC>Ge rmany</COUNTRYDESC>
<COUNTRYCODE>95 8</COUNTRYCODE>
</COUNTRY>

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

<COUNTRY>
<COUNTRYDESC>Af ghanistan</COUNTRYDESC>
<COUNTRYCODE>95 8</COUNTRYCODE>
</COUNTRY>

I'll be very grateful for any help!

Jul 20 '05 #2

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

Similar topics

0
1564
by: Ognen Ivanovski | last post by:
Is the following constraint possible to be expressed with XML Schema (and how): Suppose we have a document in the form <car type="ford"> <part name="door"/> <part name="ashtray"/> </car>
0
1630
by: Olaf Meyer | last post by:
I'm wondering if I can also express uniquness constraints on attributes of objects that I have referenced from somewhere else. To be a bit more precise here a short and simple XML document. The "objects" have a key constraint on the id attribute, i.e. they need to be unique. The object-ref element may reference the previously defined objects and hence has a keyref constraint on the id attribute. I would now like to furhter restrict the...
0
3275
by: peterpeter | last post by:
Hi. There is a XML schema problem that I have with key/keyref: I have two complex (A and B) types which both inherit from a common base typ (Base). A refers B using a xs:IDREF element named Ref_to_A. Both are allowed to be instantiated under the root element by declaring an element of the base class. I want to have type safety for the reference by using key/keyref.
0
1072
by: johnsocs | last post by:
All I'm trying to write an xml schema for the following xml from the google web service api. In the schema I'm not sure how to describe the soapenv:encodingStyle attribute. Thanks. <?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
3
2618
by: johnsocs | last post by:
All - I am very stuck on building a schema for the following xml message. I feel I'm very close as the message validates if I remove the soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" attribute from the doSpellingSuggestion element. Any help/pointers for describing the encodingStyle attribute in my schema would be great. Any help on this would be great.
4
2508
by: Iain A. Mcleod | last post by:
Hi I'm stuck with the following schema validation problem in VS.NET 2003: I have two types of xml document and related schema: project and projectCollection. A projectcollection is just a set of projects. Therefore, I wish to include the project customType in the projectCollection namespace. I therefore have declared two xsd documents: project.xsd and projectcollection.xsd
1
1565
by: Mr. Almenares | last post by:
Hello: I’m trying to do a schema with recurrent structure for a Book like a Node can have many Nodes inside or One leave. So, the leaves have an attribute that is Identifier. My goal is define Uniqueness that guarantees to the attribute Identifier his uniqueness. That I don’t know the depth of levels I have to put in the xpath attribute of the selector something like this TOC/descendant::Tree/Data, but this is not allow. How I can...
7
7386
by: Robert Stearns | last post by:
I ran the following bit of SQL and my PRIMARY KEY wound up in schema SYSIBM called SQL.... not schema is3 called primary. The index registation did wind up there. Obviously there's something I don't understand or see. If you have some insight into this problem that you are willing to share, I'd be grateful. One possibility is the uniqueness required: is the constraint required to be unique with table, schema or database? PS: Ignore the...
6
8970
by: Emma Middlebrook | last post by:
Hi there, I have created an XmlSchema to represent the tables in my database and I have specified a primary key for each of the tables. However, to be able to execute the following code: DatabaseTables.CategoryInfoRow categoryRow = m_dtCategories.Rows.Find(selected.category_ID) as DatabaseTables.CategoryInfoRow;
0
2826
by: icesign | last post by:
I know that the selector of these elements has a scope relative to the element being declared, but maybe there is a way to get beyond bounds of this scope or maybe just a way to extend base element? Here’s a working example: <xs:schema id="schema" targetNamespace="http://tempuri.org/schema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/schema.xsd" xmlns:mstns="http://tempuri.org/schema.xsd" ...
0
9669
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10154
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5430
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2913
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.