【问题标题】:How do you specify an XSD that allows a range of elements in any order?如何指定一个允许以任意顺序排列的一系列元素的 XSD?
【发布时间】:2010-02-05 21:51:10
【问题描述】:

我有一些看起来像这样的 XSD:

<element name="a">
  <complexType>
    <sequence>
      <element name="b" type="t:typ" minOccurs="1" maxOccurs="unbounded" />
      <element name="c" type="t:typ" minOccurs="1" maxOccurs="unbounded" />
    </sequence>
  </complexType>
</element>

我将如何改变它,而不是一个序列,我可以允许标签 b 和 c 以任何顺序混乱,例如我怎样才能使它有效?..

<a>
  <b />
  <c />
  <b />
  <c />
  <b />
  <b />
</a>

“all”选项听起来很有希望,但它似乎只允许每个子元素不超过一个。

【问题讨论】:

  • 一个序列可能会做,但这是一个配置文件。我希望通过不强制用户按任何特定顺序放置元素来让用户轻松编辑。

标签: xml xsd


【解决方案1】:

我相信你想要这个:

<element name="a">
  <complexType>
    <choice maxOccurs="unbounded">
      <element name="b" type="t:typ" />
      <element name="c" type="t:typ" />
    </choice>
  </complexType>
</element>

【讨论】:

  • 有趣的方法!我在想它是行不通的,因为 只允许它的一个子元素 - 但是 上的 maxOccurs=unbounded 可能会起作用!
  • 似乎可行,谢谢 :) 下一个问题是尝试将其中一个选项限制为仅一个实例......另一个问题,我想。
【解决方案2】:

你能尝试一个无限的选择元素序列吗?像这样的东西? (未经测试)

<element name="a"> 
  <complexType> 
    <sequence maxOccurs="unbounded" minOccurs="0">
      <choice> 
        <element name="b" type="t:typ" /> 
        <element name="c" type="t:typ" /> 
      </choice>
    </sequence>
  </complexType> 
</element> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-11
    • 1970-01-01
    • 2020-08-05
    • 1970-01-01
    相关资源
    最近更新 更多