简体   繁体   中英

How to mix indicators in XSD

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM