I have an XSD 1.0 sequence that defines a set of elements, some of which may be optional but none of which can occur more than once, and which also ends with an
No, in XSD 1.0, once you've allowed any element, you can't specify further constraints beyond those afforded by minOccurs
, maxOccurs
, namespace
, and processContents
.
In XSD 1.1, you can also make xsd:assertions
against the xsd:any
elements; you'd be able to express your constraint with an assertion. [Update: Don't miss @C. M. Sperberg-McQueen's simpler idea for XSD 1.1: xsd:any/@notQName="itemA itemB itemC"
]
Perhaps the simplest way to ensure that the elements itemA
, itemB
, and itemC
are not repeated is to use namespace="##other"
instead of namespace="##any"
. (This assumes that elements in the namespace testxsd
other than those three will not need to appear here.)
Or move to XSD 1.1 and add the attribute notQName="itemA itemB itemC"
.