views:

18

answers:

1

I have an xml that comes in two forms

<root>
     <element1 req="mandatory"/>
     <element2/>
     <element3/>
<root>

and

<root>
     <element2/>
     <element3/>
     <element4 req="mandatory"/>
<root>

element1 or elem4 is req'd 2 and 3 are optional. I just cant figure out how to use a xsd:choice on it, help, thanks.

A: 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="root">
    <xs:complexType>
        <xs:choice>
            <xs:sequence>
                <xs:element name="element1"/>
                <xs:element name="element2" minOccurs="0"/>
                <xs:element name="element3" minOccurs="0"/>
            </xs:sequence>
            <xs:sequence>
                <xs:element name="element2" minOccurs="0"/>
                <xs:element name="element3" minOccurs="0"/>
                <xs:element name="element4"/>
            </xs:sequence>
        </xs:choice>
    </xs:complexType>
</xs:element>

jwismar
I could have swore I tried that....and now it works...Maybe Ive been working too hard and should stop for the day....thanks!
jtzero