Xsd XML模式-maxOccurs在choice元素中

Xsd XML模式-maxOccurs在choice元素中,xsd,Xsd,我有以下模式声明: <element name="container"> <complexType> <choice minOccurs="0" maxOccurs="unbounded"> <element name="action" minOccurs="0" maxOccurs="1" /> <element name="query" minOccurs="0" maxOccurs="unbounde

我有以下模式声明:

<element name="container">
  <complexType>
    <choice minOccurs="0" maxOccurs="unbounded">
      <element name="action" minOccurs="0" maxOccurs="1" />
      <element name="query" minOccurs="0" maxOccurs="unbounded" />
      <element name="validator" minOccurs="0" maxOccurs="unbounded" />
    </choice>
  </complexType>
</element>

我基本上希望一个
包含所需数量的
元素,但只有一个
元素(可能没有)

据我所知,我不能将maxOccurs放在
上,因为从技术上讲,可以进行无限次的选择(由于查询和验证器上的未绑定)

然而,这种XML在Eclipse中被认为是有效的(这在Eclipse验证中可能是个问题,尽管所有其他位都可以正常工作)



不确定我是否遗漏了一些明显的内容。

您当前的模型定义了(a)一个
操作
元素或无,(b)零个或多个
查询
元素,或(c)零个或多个
验证程序
元素,然后允许该选择重复零次或多次。因此,它相当于

<choice minOccurs="0" maxOccurs="unbounded">
  <element name="action"/>
  <element name="query"/>
  <element name="validator"/>
</choice>
有时,不同种类的元素发生的顺序传递信息,因此有必要让它们混合在一起。在这种情况下,问题类似于下面的正则表达式问题:编写一个正则表达式,定义由“a”、“q”和“v”组成的字符串集,其中“a”最多出现一次。一个明显的正则表达式是
(q | v)*(a(q | v)?
。类似的XSD模型组为:

<sequence>
  <choice minOccurs="0" maxOccurs="unbounded">
    <element ref="query"/>
    <element ref="validator"/>
  </choice>
  <sequence minOccurs="0">
    <element name="action"/>
    <choice minOccurs="0" maxOccurs="unbounded">
      <element ref="query"/>
      <element ref="validator"/>
    </choice>
  </sequence>
</sequence>

请编辑这句关键的句子,使其易懂:“我基本上希望a包含所需的或元素,但只有一个元素(可能没有)。”我没有注意到标签名没有出现在最后一篇文章中,对不起-感谢CM的编辑。回答很好-我可以使用该元素,因此,这很好地完成了任务,并保持了模式的整洁。谢谢!
<sequence>
  <element name="action" minOccurs="0" maxOccurs="1" />
  <element name="query" minOccurs="0" maxOccurs="unbounded" />
  <element name="validator" minOccurs="0" maxOccurs="unbounded" />
</sequence>
<sequence>
  <choice minOccurs="0" maxOccurs="unbounded">
    <element ref="query"/>
    <element ref="validator"/>
  </choice>
  <sequence minOccurs="0">
    <element name="action"/>
    <choice minOccurs="0" maxOccurs="unbounded">
      <element ref="query"/>
      <element ref="validator"/>
    </choice>
  </sequence>
</sequence>
<all>
  <element name="action" minOccurs="0" maxOccurs="1" />
  <element name="query" minOccurs="0" maxOccurs="unbounded" />
  <element name="validator" minOccurs="0" maxOccurs="unbounded" />
</all>