all groups > dotnet xml > october 2005 >
You're in the

dotnet xml

group:

xsd, how to...


xsd, how to... Sergey Poberezovskiy
10/27/2005 7:07:01 PM
dotnet xml:
Hi,

I need to implement the following rule:
Element el_1 is defined as follows:

<xs:element name="el_1">
<xs:restriction base="xs:string">
<xs:enumeration value="value1"/>
<xs:enumeration value="value2"/>
<xs:enumeration value="value3"/>
</xs:restriction>
</xs:element>

If in validated XML document el_1 = value1 then I need elements 2 and 3 to
appear, otherwise - 4 and five. Something like:

<xs:choice>
<xs:sequence>
<xs:element name="el_1" with_value="value1"/>
<xs:element ref="el_2"/>
<xs:element ref="el_3"/>
</xs:sequence>
<xs:sequence>
<xs:element name="el_1" with_value!="value1"/>
<xs:element ref="el_4"/>
<xs:element ref="el_5"/>
</xs:sequence>
<xs:choice>

I know that the code above is not valid, what I do not know - how to make it
valid?

Any help is appreciated.
Re: xsd, how to... Zafar Abbas
10/28/2005 11:03:27 AM
Such a choice of sequences would violate the UPA rule from the XSD schema
spec. In this case e1_1 can not be present as a start element for two
sequence under the same choice, since the validator could get confusesd
which e1_1 to start with.

Co occurence constraints like this are not representable using XML Schema.
Consider schematron.


[quoted text, click to view]

Re: xsd, how to... Stan Kitsis [MSFT]
10/28/2005 11:05:51 AM
You cannot do this in XSD.
Your best option is probably to create distinct elements <value1> and
<value2> and then have a choice
<xs:choice>
<xs:sequence>
<xs:element name="value1">
<xs:element name="element2">
<xs:element name="element3">
<xs:sequence>
<xs:sequence>
<xs:element name="value2">
<xs:element name="element4">
<xs:element name="element5">
<xs:sequence>
</xs:choice>

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


[quoted text, click to view]

AddThis Social Bookmark Button