XSD里面的所有选择 [英] XSD choice inside all

查看:14
本文介绍了XSD里面的所有选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您不能将选择标签放在所有标签内.那么,是否有任何解决方法来获得此功能?例如,我有 <settings> 标签,例如:

You can't put choice tag inside the all tag. So, is there any workaround to get this functionallity? For example, I have<settings> tag like:

<settings>
    <logging />
    <sending />
    <useonly />
</settings>

或者类似的东西

<settings>
    <logging />
    <notuseonly />
    <sending />
</settings>

所以我想防止 <useonly><notuseonly> 一起出现,而顺序并不重要.如果允许,在 XSD 中它看起来像:

So I want to prevent <useonly> and <notuseonly> showing up together, while the order is not important. And if allowed, in XSD it would look like:

  <xs:all>
    <xs:element minOccurs="0" maxOccurs="1" ref="sending" />
    <xs:element minOccurs="0" maxOccurs="1" ref="logging" />
    <xs:choice>
         <xs:element minOccurs="0" maxOccurs="1" ref ="useonly" />
         <xs:element minOccurs="0" maxOccurs="1" ref ="notuseonly" />
     </xs:choice>
  </xs:all>

有什么想法吗?

推荐答案

查看此链接:http://www.w3.org/wiki/Needs_choice_inside_all

我为你总结了提出的解决方案:

I summarize for you the solutions proposed:

一种解决方案是将可以更改的元素包装在另一个元素中:

One solution is to wrap the element that can change inside another:

  <xsd:all>
   <xsd:element minOccurs="0" maxOccurs="1" ref="sending" />
   <xsd:element minOccurs="0" maxOccurs="1" ref="logging"/>
   <xsd:element minOccurs="0" maxOccurs="1" ref ="usetype"/>
  </xsd:all>

 <xsd:element name="usetype">
  <xsd:complexType>
   <xsd:choice>
    <xsd:element ref="useonly"/>
    <xsd:element ref="notuseonly"/>
   </xsd:choice>
  </xsd:complexType>
 </xsd:element>

另一种是使用替换组:

  <xsd:all>
   <xsd:element ref="sending"/>
   <xsd:element ref="logging"/>
   <xsd:element ref="usetype"/>
  </xsd:all>
 </xsd:complexType>
 <xsd:element name="usetype" abstract="true"/>
 <xsd:element name="useonly" substitutionGroup="usetype"> ... </xsd:element>
 <xsd:element name="notuseonly" substitutionGroup="usetype"> ... </xsd:element>

这篇关于XSD里面的所有选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆