简体   繁体   English

如何在XSD中混合指标

[英]How to mix indicators in XSD

I have the following XML snippet 我有以下XML代码段

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

which is validated by this XSD 该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>

I need to change the XSD so it will also validate the following: 我需要更改XSD,因此它还将验证以下内容:

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

Apparently xs:choice is used for this kind of thing, but I'm not sure how to incorporate it. 显然xs:choice用于这种事情,但是我不确定如何将其合并。 Any ideas? 有任何想法吗?

You need to change all , to sequence , and create a choice between field and fields . 你需要改变all ,以sequence ,并创造之间做出选择fieldfields Section 2.7 building content models of the XML Schema Primer gives an example of using sequence and choice in this way. 第2.7节构建 XML Schema Primer的内容模型给出了以这种方式使用序列和选择的示例。

I would also recommend defining field elsewhere, and using xs:element/@ref to point to it, so that you don't repeat it. 我还建议您在其他地方定义field ,并使用xs:element/@ref指向它,以免重复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM