xml – How to mix indicators in XSD – Education Career Blog

I have the following XML snippet


which is validated by this XSD

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

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


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.

Leave a Comment