开发者

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

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?


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜