简体   繁体   English

描述W3C XML模式中重复的XML节点?

[英]Describe repeating XML nodes in W3C XML Schema?

I have an XML document like: 我有一个XML文档,例如:

<Root>
    <Bravo />
    <Alpha />
    <Charlie />
    <Charlie />
    <Delta />
    <Foxtrot />
    <Charlie />
</Root>

The order of the nodes does not matter. 节点的顺序无关紧要。 Each node may appear zero or one times, except for Charlie. 除了查理,每个节点可能出现零次或一次。 Charlie may appear zero, one, or arbitrarily many times. 查理可能出现零次,一次或任意多次。 The straightforward way to express this in XSD is: 在XSD中表达这一点的直接方法是:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="Root">
        <xsd:complexType>
            <xsd:all>
                <xsd:element name="Alpha" minOccurs="0" maxOccurs="1" />
                <xsd:element name="Bravo" minOccurs="0" maxOccurs="1" />
                <xsd:element name="Charlie" minOccurs="0" maxOccurs="unbounded" />
                <xsd:element name="Delta" minOccurs="0" maxOccurs="1" />
                <xsd:element name="Echo" minOccurs="0" maxOccurs="1" />
                <xsd:element name="Foxtrot" minOccurs="0" maxOccurs="1" />
            </xsd:all>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

But this does not work, because xsd:all does not allow for maxOccurs greater than 1. Since I cannot use xsd:all, what should I use? 但这是行不通的,因为xsd:all不允许maxOccurs大于1。由于我不能使用xsd:all,应该使用什么?

Schematron. Schematron。 :) :)

I am not 100% sure, but I think this model cannot be expressed in XML Schema. 我不确定100%,但是我认为该模型无法用XML Schema表示。

You could use xsd:sequence, but then the order would be important which you have stated in the question will not be guaranteed. 您可以使用xsd:sequence,但是顺序将很重要,您在问题中所说的顺序将无法保证。

Looking at: http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#element-group it seems that there is not a model group that you can use, although maybe you could just define them in the complexType without using a content group? 查看: http : //www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#element-group似乎没有可以使用的模型组,尽管也许可以只是在complexType中定义它们而不使用内容组?

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

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