How to make an element appear anywhere in XML Schema [duplicate]
I need an element to appear anywhere any amount of times. What is the easiest way to do it? If I have other elements, it wouldn't be wise to just put it inside everyone as an optional.
In general, you cannot do this as you will have a non-deterministic model.
For example, you cannot have a sequence group like:
<xs:sequence>
<!-- X is the element that may appear anywhere -->
<xs:element name="X" minOccurs="0"/>
<xs:element name="Y" minOccurs="0" maxOccurs="5"/>
<xs:element name="X" minOccurs="0"/>
</xs:sequence>
In the above, an occurrence of element X could validate against the first or second declaration of X. This violates the "Unique Particle Attribution" (UPA) requirement.
It may be that no schema can recognize precisely the language you want. Or, perhaps your particular language can be accommodated if you can see your way to avoiding UPA violations. For example, if Y above had not been optional (if minOccurs had equaled maxOccurs), then UPA would not have been violated.
精彩评论