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...