Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 如何使标记子项唯一?_Xml_Validation_Xsd_Schema - Fatal编程技术网

Xml 如何使标记子项唯一?

Xml 如何使标记子项唯一?,xml,validation,xsd,schema,Xml,Validation,Xsd,Schema,如何在xml文件的限制标记中禁止重复标记? 例如,在我的xml文件中,我有两个locale标记,但它应该只有一个标记 这是我的xml文件: <app:string name="firstName"> <app:restriction> <app:regex>^\w*$</app:regex> <app:type/> <app:local

如何在xml文件的限制标记中禁止重复标记? 例如,在我的xml文件中,我有两个locale标记,但它应该只有一个标记

这是我的xml文件:

    <app:string name="firstName">
        <app:restriction>
            <app:regex>^\w*$</app:regex>
            <app:type/>
            <app:locale/>
            <app:locale/>
        </app:restriction>
    </app:string>

^\w*$
这是我的xsd for字符串标记:

<xs:element name="string">
    <xs:complexType>
        <xs:complexContent>
            <xs:extension base="main:BaseType">
                <xs:sequence>
                    <xs:element name="restriction" type="main:StringRestriction" minOccurs="0"
                                maxOccurs="1"/>
                </xs:sequence>
                <xs:attribute name="lang" type="main:LocaleTypes"/>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
</xs:element>

<xs:complexType name="BaseType">
    <xs:attribute name="name" type="main:nameType" use="required"/>
    <xs:attribute name="readonly" type="xs:boolean" use="optional" default="true"/>
</xs:complexType>

<xs:complexType name="StringRestriction">
    <xs:complexContent>
        <xs:extension base="main:RestrictionBase">
            <xs:sequence>
                <xs:choice maxOccurs="1">
                    <xs:element type="xs:string" name="locale"/>
                    <xs:element type="xs:string" name="type"/>
                    <xs:element type="xs:string" name="regex"/>
                    <xs:element type="xs:string" name="maxLen"/>
                    <xs:element type="xs:string" name="minLen"/>
                </xs:choice>
            </xs:sequence>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

如果我理解正确,您需要一个模式,强制您的
限制
标记包含标记而不重复

如果您将其替换为:

<xs:sequence>
    <xs:choice maxOccurs="1">
        <xs:element type="xs:string" name="locale"/>
        <xs:element type="xs:string" name="type"/>
        <xs:element type="xs:string" name="regex"/>
        <xs:element type="xs:string" name="maxLen"/>
        <xs:element type="xs:string" name="minLen"/>
    </xs:choice>
</xs:sequence>

为此:

<xs:all minOccurs="0">
    <xs:element type="xs:string" name="locale"/>
    <xs:element type="xs:string" name="type"/>
    <xs:element type="xs:string" name="regex"/>
    <xs:element type="xs:string" name="maxLen"/>
    <xs:element type="xs:string" name="minLen"/>
</xs:all>

您的架构不允许在
限制
标记中重复
区域设置
元素。 您可以在此处看到摘要:
除此之外,您还可以使用
minOccurs
maxOccurs
强制某些元素始终显示,而其他元素只是可选的。

序列是一个排序列表,但我需要一个未排序的列表。因此,我使用了带选项的序列在这种情况下,您可以用xsd:all元素替换xsd:sequence元素。xsd:all指定子元素可以以任何顺序出现,并且每个子元素可以出现零次或一次。