XML Schema with complext type containing <xs:all> and <xs:any>?

ε祈祈猫儿з 提交于 2019-12-10 14:37:05

问题


I want to define a complex type that contains elements that may or may not exist, and also allows for additional undefined elements so I've got something like this:

<xs:complexType name="MyType">
 <xs:sequence>
  <xs:element name="A" type="xs:float" minOccurs="0" maxOccurs="1" />
  <xs:element name="B" type="xs:float" minOccurs="0" maxOccurs="1" />
  <xs:element name="C" type="xs:float" minOccurs="0" maxOccurs="1" />
  <xs:any minOccurs="0" processContents="skip"/>
 </xs:sequence>
</xs:complexType>

I don't want to force the order using <xs:sequence> so I want to change the <xs:sequence> to <xs:all> but then <xs:any> isn't allowed. Is there some way to accomplish this?


回答1:


To allow any order, use this:

<xs:complexType name="MyType"> 
 <xs:all minOccurs="1" maxOccurs="1"> 
  <xs:element name="A" type="xs:float" minOccurs="0" maxOccurs="1" />
  <xs:element name="B" type="xs:float" minOccurs="0" maxOccurs="1" />
  <xs:element name="C" type="xs:float" minOccurs="0" maxOccurs="1" />
 </xs:all>
</xs:complexType> 

But then, you can't have an <any> inside an <all>.
Nor can you have them both inside one type, either directly or as an extension.



来源:https://stackoverflow.com/questions/3367085/xml-schema-with-complext-type-containing-xsall-and-xsany

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!