Xml 唯一粒子违规

Xml 唯一粒子违规,xml,schema,xsd,Xml,Schema,Xsd,我已经研究这个问题太久了。我怀疑我错过了一些明显的东西,因为我对它太熟悉了 我有一个模式存在唯一的粒子冲突错误。我明白为什么,但我花了太长时间摆弄它,以至于无法退一步解决问题 我如何表达这个模式,以便它能够验证我需要建模的内容 内容模型类似于: <document> <extract>...</extract> <structure>...</structure> <structure>...<

我已经研究这个问题太久了。我怀疑我错过了一些明显的东西,因为我对它太熟悉了

我有一个模式存在唯一的粒子冲突错误。我明白为什么,但我花了太长时间摆弄它,以至于无法退一步解决问题

我如何表达这个模式,以便它能够验证我需要建模的内容

内容模型类似于:

<document>
    <extract>...</extract>
    <structure>...</structure>
    <structure>...</structure>
</document>

...
...
...


...
...


...
...
文档元素可以包含一个或多个提取元素或一个或多个结构元素,也可以包含一个提取元素,后跟一个或多个结构元素

我有一个(不正确的)架构,看起来像:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="document" type="Document"/>
    <xs:complexType name="Document">
        <xs:choice>
            <xs:sequence>
                <xs:element ref="extract" minOccurs="0"/>
                <xs:element ref="structure" minOccurs="1" maxOccurs="unbounded"/>
            </xs:sequence>
            <xs:element maxOccurs="unbounded" ref='extract'/>
        </xs:choice>
    </xs:complexType>

    <xs:element name="extract" type="xs:string"/>
    <xs:element name="structure" type="xs:string"/>

</xs:schema>

(这是对更复杂模式的精简验证)

干杯


nic

因此您需要DTD样式的内容模型:

extract+|structure+|extract,structure+
这里的问题是,
提取的存在并不能确定采用哪个分支。但我们可以像这样重写内容模型:

extract,(structure+|extract*)|structure+
你可以看到,如果你像代数一样“展开”内部选择,这是相同的:

extract,structure+|extract,extract*|structure+
extract,structure+|extract+|structure+     [[ extract,extract* === extract+ ]]
此内容模型可以转换回XSD:

<xs:complexType name="Document">
 <xs:choice>
  <xs:sequence>
   <xs:element ref="extract"/>
   <xs:choice>
    <xs:element ref="structure" maxOccurs="unbounded"/>
    <xs:element ref="extract" minOccurs="0" maxOccurs="unbounded"/>
   </xs:choice>
  </xs:sequence>
  <xs:element ref="structure" maxOccurs="unbounded"/>
 </xs:choice>
</xs:complexType>

就是这样-我知道我已经看这个太久了。非常感谢。
extract,structure+|extract,extract*|structure+
extract,structure+|extract+|structure+     [[ extract,extract* === extract+ ]]
<xs:complexType name="Document">
 <xs:choice>
  <xs:sequence>
   <xs:element ref="extract"/>
   <xs:choice>
    <xs:element ref="structure" maxOccurs="unbounded"/>
    <xs:element ref="extract" minOccurs="0" maxOccurs="unbounded"/>
   </xs:choice>
  </xs:sequence>
  <xs:element ref="structure" maxOccurs="unbounded"/>
 </xs:choice>
</xs:complexType>