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

xsd:xs:sequence&xs:choice组合用于xs:extension元素?

  •  1
  • bguiz  · 技术社区  · 15 年前

    我的问题是定义一个xml模式,该模式将验证以下示例xml:

    <rules>
        <other>...</other>
        <bool>...</bool>
        <other>...</other>
        <string>...</string>
        <other>...</other>
    </rules>
    

    子节点的顺序无关紧要。子节点的基数为0..unbounded。

    的所有子元素 rules 节点有一个公共的基类型, rule ,像这样:

    <xs:complexType name="booleanRule">
        <xs:complexContent>
            <xs:extension base="rule">
                ...
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    
    <xs:complexType name="stringFilterRule">
        <xs:complexContent>
            <xs:extension base="filterRule">
                ...
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    

    我当前试图为 规则 节点在下面。然而,

    1. 我可以筑巢吗? xs:choice 在内部 xs:sequence ?如果,我在哪里指定 maxOccurs="unbounded" 属性?
    2. 有没有更好的方法,比如 序列: 哪个只指定其子元素的基类型?

          <xs:element name="rules">
              <xs:complexType>
                  <xs:sequence>
                      <xs:choice>
                          <xs:element name="bool" type="booleanRule" />
                          <xs:element name="string" type="stringRule" />
                          <xs:element name="other" type="someOtherRule" />
                      </xs:choice>
                  </xs:sequence>
              </xs:complexType>
          </xs:element>
      
    1 回复  |  直到 15 年前
        1
  •  3
  •   lexicore    15 年前
    1. 是的,你可以。您可以指定 maxOccurs="unbounded" 更适合你的地方。你可以穿上它 xs:choice ,例如(我想这就是你的要求)。
    2. 可以使用替换组。见 this schema 例如。 ogc:expression 是一个抽象基元,可以用不同的具体表达式替换( ogc:Add 等等。