代码之家  ›  专栏  ›  技术社区  ›  Manos Dilaverakis

如何在XSD中混合指标

  •  1
  • Manos Dilaverakis  · 技术社区  · 14 年前

    我有以下XML代码段

    <restriction>
        <name>notempty</name>
        <field>title</field>
    </restriction>
    

    由该XSD验证

    <xs:element name="restriction" maxOccurs="unbounded">
        <xs:complexType>
            <xs:all>
                <xs:element name="name" type="xs:string" minOccurs="1" />
                <xs:element name="field" type="xs:string" />
            </xs:all>
        </xs:complexType>
    </xs:element>
    

    我需要更改XSD,这样它还将验证以下内容:

    <restriction>
       <name>notempty</name>
       <fields>
           <field>title</field>
           <field>info</field>
       </fields>
    </restriction>
    

    显然,选择是用来做这类事情的,但我不知道如何合并它。有什么想法吗?

    1 回复  |  直到 14 年前
        1
  •  0
  •   Paul Butcher    14 年前

    你需要改变 all ,为了 sequence ,并在 field fields . Section 2.7 building content models XML模式入门提供了一个以这种方式使用序列和选择的示例。

    我还建议定义 领域 在其他地方使用 xs:element/@ref 指向它,这样你就不会重复它了。