开发者

How to restrict an xs:choice containing xs:any?

If I have a xs:complexType that conatins this:

<xs:choice minOccurs='0' maxOccurs='unbounded'>
   <xs:any/>
</xs:choice>

I understand that xs:any meany any valid element, but normally, I wouldn't 开发者_高级运维want my root element to be used anywhere except as root, so can I prevent that by saying 'any except the root (or any other specific) element' ?


I think an ideal solution would be to refactor the schema so that you have one type that does not include <xs:any/> and another one with it <xs:any/>, that is if you really have to use if for some reason. In general <xs:any/> is a very strong statement that throws the validation out of the window as it pretty much allows anything from any namespace, having said that what you're probably after here is processContents="strict" or processContents="lax" attribute, so:

<xsd:any processContents="strict"/>

means that for any namespace it will have to validate against a schema, even if the schema doesn't exists or (probably better for your case):

This will only require validation if the schema exists.

Because you are defining a schema for your own namespace, this will work - ie if you try to use a root element from your own/default namspace - it will validate it against that namespace and tell you it's not allowed.

You can refer to the W3C Spec for more details.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜