代码之家  ›  专栏  ›  技术社区  ›  izb

您如何指定一个XSD,允许以任何顺序排列一系列元素?

  •  4
  • izb  · 技术社区  · 15 年前

    我有一些像这样的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>
    

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

    2 回复  |  直到 15 年前
        1
  •  4
  •   CoderDennis    15 年前

    我相信你想要这个:

    <element name="a">
      <complexType>
        <choice maxOccurs="unbounded">
          <element name="b" type="t:typ" />
          <element name="c" type="t:typ" />
        </choice>
      </complexType>
    </element>
    
        2
  •  0
  •   Simon Nickerson    15 年前

    你能试试无边界的选择元素序列吗?像这样?(未经测试)

    <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>