tags:

views:

24

answers:

1

I have the following XML snippet

<restriction>
    <name>notempty</name>
    <field>title</field>
</restriction>

which is validated by this XSD

<xs:element name="restriction" maxOccurs="unbounded">
    <xs:complexType>
        <xs:all>
            <xs:element name="name" type="xs:string" minOccurs="1" />
            <xs:element name="field" type="xs:string" />
        </xs:all>
    </xs:complexType>
</xs:element>

I need to change the XSD so it will also validate the following:

<restriction>
   <name>notempty</name>
   <fields>
       <field>title</field>
       <field>info</field>
   </fields>
</restriction>

Apparently xs:choice is used for this kind of thing, but I'm not sure how to incorporate it. Any ideas?

A: 

You need to change all, to sequence, and create a choice between field and fields. Section 2.7 building content models of the XML Schema Primer gives an example of using sequence and choice in this way.

I would also recommend defining field elsewhere, and using xs:element/@ref to point to it, so that you don't repeat it.

Paul Butcher
This worked although it's annoying I can't keep "all"
Manos Dilaverakis