473,803 Members | 3,534 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem compiling xsd with xs:choice node

Hi,

As part of my schema I need to ensure that at least one of two fields have
values. I defined my schema as follows:
....
<xs:choice>
<xs:element ref="el1"/>
<xs:element ref="el2"/>
<xs:sequence>
<xs:element ref="el1"/>
<xs:element ref="el2"/>
</xs:sequence>
</xs:choice>
....
<xs:element name="el1" type="xs:string "/>
<xs:element name="el2" type="xs:string "/>

Schema compiles just fine, but XmlValidatingRe ader validation fails when

....
<el1>value</el1>
<el2>value</el2>
....
is found in the document. (XmlSpy validates the document without errors).

Now, two questions:
- whether the schema I used is the most efficient way to solve my problem
(ensure that at least one out of two elements is specified)?
- if the schema I used is a valid choice, then show come the .Net validation
fails and how to make it work?

TIA.

P.S. I hope that there is a better way to ensure that at least 1 out of N
elements is specified, as in another document I need to do 1 out of 3, but I
take 1 step at a time...
Nov 12 '05 #1
4 1731


Sergey Poberezovskiy wrote:

<xs:choice>
<xs:element ref="el1"/>
<xs:element ref="el2"/>
<xs:sequence>
<xs:element ref="el1"/>
<xs:element ref="el2"/>
</xs:sequence>
</xs:choice>


Doesn't
<xs:choice maxOccurs="unbo unded">
<xs:element ref="el1"/>
<xs:element ref="el2"/>
</xs:choice>
suffice for what you want?
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
Martin,

that would be too easy:
I have two elements and no more than one of each can be present (both is OK)
but at least one should be specified.

"Martin Honnen" wrote:


Sergey Poberezovskiy wrote:

<xs:choice>
<xs:element ref="el1"/>
<xs:element ref="el2"/>
<xs:sequence>
<xs:element ref="el1"/>
<xs:element ref="el2"/>
</xs:sequence>
</xs:choice>


Doesn't
<xs:choice maxOccurs="unbo unded">
<xs:element ref="el1"/>
<xs:element ref="el2"/>
</xs:choice>
suffice for what you want?
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Nov 12 '05 #3
Unfortunately what you want to do is not easy using xsd. Depending on what
your requirements are, you might be able to use <xs:all> or an unbounded
choice. If this doesn't solve your problem, then you will have to expand
everything.

The schema fragment you've posted is invalid - it violates UPA:

A content model must be formed such that during validation of an element
information item sequence, the particle contained directly, indirectly or
implicitly therein with which to attempt to validate each item in the
sequence in turn can be uniquely determined without examining the content or
attributes of that item, and without any information about the items in the
remainder of the sequence.

In your particular case, when el1 appears in the XML document, it is
imposible to tell whether it is the first el1 from the choice or the one
from the sequence. Therefore, the validating reader cannot determine
whether it should be followed by el2 or not.

--
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
"Sergey Poberezovskiy" <Se************ *****@discussio ns.microsoft.co m> wrote
in message news:AC******** *************** ***********@mic rosoft.com...
Hi,

As part of my schema I need to ensure that at least one of two fields have
values. I defined my schema as follows:
...
<xs:choice>
<xs:element ref="el1"/>
<xs:element ref="el2"/>
<xs:sequence>
<xs:element ref="el1"/>
<xs:element ref="el2"/>
</xs:sequence>
</xs:choice>
...
<xs:element name="el1" type="xs:string "/>
<xs:element name="el2" type="xs:string "/>

Schema compiles just fine, but XmlValidatingRe ader validation fails when

...
<el1>value</el1>
<el2>value</el2>
...
is found in the document. (XmlSpy validates the document without errors).

Now, two questions:
- whether the schema I used is the most efficient way to solve my problem
(ensure that at least one out of two elements is specified)?
- if the schema I used is a valid choice, then show come the .Net
validation
fails and how to make it work?

TIA.

P.S. I hope that there is a better way to ensure that at least 1 out of N
elements is specified, as in another document I need to do 1 out of 3, but
I
take 1 step at a time...

Nov 12 '05 #4
Stan,

What I need to do is to put an insurance claim form into xsd schema. They
have two fields on the form and at least one has to be specified, while both
is still possible. Is that such an uncommon case that there is no simple
solution?!?

I have only started using xsds and not sure what unbounded choice is. And
what if someone need to select at least one out of three or four? -
describing all possible combinations will expand exponentially.

Please HELP!!!

"Stan Kitsis [MSFT]" wrote:
Unfortunately what you want to do is not easy using xsd. Depending on what
your requirements are, you might be able to use <xs:all> or an unbounded
choice. If this doesn't solve your problem, then you will have to expand
everything.

The schema fragment you've posted is invalid - it violates UPA:

A content model must be formed such that during validation of an element
information item sequence, the particle contained directly, indirectly or
implicitly therein with which to attempt to validate each item in the
sequence in turn can be uniquely determined without examining the content or
attributes of that item, and without any information about the items in the
remainder of the sequence.

In your particular case, when el1 appears in the XML document, it is
imposible to tell whether it is the first el1 from the choice or the one
from the sequence. Therefore, the validating reader cannot determine
whether it should be followed by el2 or not.

--
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
"Sergey Poberezovskiy" <Se************ *****@discussio ns.microsoft.co m> wrote
in message news:AC******** *************** ***********@mic rosoft.com...
Hi,

As part of my schema I need to ensure that at least one of two fields have
values. I defined my schema as follows:
...
<xs:choice>
<xs:element ref="el1"/>
<xs:element ref="el2"/>
<xs:sequence>
<xs:element ref="el1"/>
<xs:element ref="el2"/>
</xs:sequence>
</xs:choice>
...
<xs:element name="el1" type="xs:string "/>
<xs:element name="el2" type="xs:string "/>

Schema compiles just fine, but XmlValidatingRe ader validation fails when

...
<el1>value</el1>
<el2>value</el2>
...
is found in the document. (XmlSpy validates the document without errors).

Now, two questions:
- whether the schema I used is the most efficient way to solve my problem
(ensure that at least one out of two elements is specified)?
- if the schema I used is a valid choice, then show come the .Net
validation
fails and how to make it work?

TIA.

P.S. I hope that there is a better way to ensure that at least 1 out of N
elements is specified, as in another document I need to do 1 out of 3, but
I
take 1 step at a time...


Nov 12 '05 #5

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

Similar topics

3
510
by: dgaucher | last post by:
Hi, I want to consume a Web Service that returns a choice, but my C++ client always receives the same returned type. On the other hand, when I am using a Java client, it is working fine (of course, the generated proxy is not the same). When I am looking at the C++ generated code, it seems fine, but when I am executing the code, I always get the first choice type.
1
2915
by: Oleg Ogurok | last post by:
Hi all, I have a complex type defined as follows: <xs:complexType name="SchedulingMethodType"> <xs:choice maxOccurs="1"> <xs:element name="Interval" type="xs:duration" /> <xs:element name="DailyAt" type="xs:duration" /> </xs:choice> </xs:complexType>
2
2374
by: Matthew | last post by:
I have implemented the xmlSchemaCollection object to cache commonly used schemas, as follows: =============================================================================== public void SchemaValidate(XmlDocument xmlDoc, string schemaURI, string urnNamespace) {
2
5664
by: pawel.pabich | last post by:
Hajo, I know only one way of forcing element to have one or more childes: <xs:element name="saleOrSupplyMethod"> <BR/> <xs:complexType> <xs:choice> <xs:sequence> <xs:element name="generalSale" type="emptyTagType" /> <xs:element name="prescription" type="emptyTagType"/>
7
2459
by: rbarschaw | last post by:
I have the following schema designed: <xs:complexType name="AzzFeature-BoxType" mixed="true"> <xs:choice minOccurs="1" maxOccurs="unbounded"> <xs:element ref="Sub-Head" minOccurs="1" maxOccurs="unbounded"/> <xs:element ref="Title-Text" minOccurs="0" maxOccurs="unbounded"/> <xs:element ref="Text" minOccurs="0" maxOccurs="unbounded"/> <xs:element ref="Link-List" minOccurs="0" maxOccurs="unbounded"/> </xs:choice> <xs:attribute...
2
3139
by: mavis | last post by:
The usage of <xs:choice maxOccurs="unbounded"> When we want to define a set of elements that could be in any order and with any occurences (0-unbounded), we can use <xs:choice maxOccurs="unbounded"> But I alway think that is not a good schema definition for XML files, and it must influence the writing and reading performance of these set of elements if there are large amounts of sub-elements. We can imagine that the retrieval of any...
2
1673
by: hooomee | last post by:
Given: <xs:choice maxOccurs=5> <xs:element name="Foo" type="bar" /> <xs:element name="Foo1" type="bar" /> <xs:element name="Foo2" type="bar" /> </xs:choice> Is the choice made once and then the choosen element can occur 5 times, or is the choice made once for each occurance?
2
1356
by: cmay | last post by:
I am beginning to wonder if it is not possible to get this working. I am trying to do: <root> <a/> <b/> <c/> </root>
0
2145
by: =?Utf-8?B?RGFtaWFu?= | last post by:
(This is using .net version 2.0.50727 and system.xml 2.0.50727.42) I am getting an error when serializing using classes generated by xsd.exe. The error is of the type "The Type <typewas not expected. Use the XmlInclude or SoapInclude etc" This error is appearing sprodically, with no obvious pattern. When it occurs, it happens every time we run the code, however changes to our code in creating the objects before they are serialized...
0
9703
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
10317
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
10295
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
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5501
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...
0
5633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.