开发者

How to make an element appear anywhere in XML Schema [duplicate]

This question already has开发者_如何学C answers here: How to allow an XML element to appear anywhere via XSD? (3 answers) Closed 5 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜