473,385 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 XmlValidatingReader 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 1699


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="unbounded">
<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="unbounded">
<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*****************@discussions.microsoft.com> wrote
in message news:AC**********************************@microsof t.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 XmlValidatingReader 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*****************@discussions.microsoft.com> wrote
in message news:AC**********************************@microsof t.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 XmlValidatingReader 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
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...
1
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...
2
by: Matthew | last post by:
I have implemented the xmlSchemaCollection object to cache commonly used schemas, as follows: =============================================================================== public void...
2
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...
7
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"...
2
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...
2
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...
2
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
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.