XML 架构中的唯一粒子属性违规
Unique Particle Attribution violation in XML schema
为什么以下 XML 在我验证时给出 UPA 违规?
<xs:element name='Information'>
<xs:complexType>
<xs:choice>
<xs:element ref='ID'/>
<xs:sequence>
<xs:element ref='ID'/>
<xs:element ref='Name'/>
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name='ID' type="xs:integer"/>
<xs:element name='Name' type="xs:string"/>
这不是简单地说明 Information 是整数 OR 和整数和字符串吗?歧义在哪里?在 xml 模式方面没有受过很好的教育,所以我可能遗漏了一些简单的东西......
它是有歧义的,因为当解析器"comes"到<ID>
元素时,它不能select适当的内容模型(这里是<ID>
单独,或者<ID>
然后 <Name>
) 文档中没有 "looking further"。
您需要使用这样定义的内容模型(它与您想要的完全相同):
<xs:element name='Information'>
<xs:complexType>
<xs:sequence>
<xs:element ref='ID'/>
<xs:element ref='Name' minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
为什么以下 XML 在我验证时给出 UPA 违规?
<xs:element name='Information'>
<xs:complexType>
<xs:choice>
<xs:element ref='ID'/>
<xs:sequence>
<xs:element ref='ID'/>
<xs:element ref='Name'/>
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name='ID' type="xs:integer"/>
<xs:element name='Name' type="xs:string"/>
这不是简单地说明 Information 是整数 OR 和整数和字符串吗?歧义在哪里?在 xml 模式方面没有受过很好的教育,所以我可能遗漏了一些简单的东西......
它是有歧义的,因为当解析器"comes"到<ID>
元素时,它不能select适当的内容模型(这里是<ID>
单独,或者<ID>
然后 <Name>
) 文档中没有 "looking further"。
您需要使用这样定义的内容模型(它与您想要的完全相同):
<xs:element name='Information'>
<xs:complexType>
<xs:sequence>
<xs:element ref='ID'/>
<xs:element ref='Name' minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>