目的: 我有一个名为Schema1.xsd的现有标准XSD。 我想在Schema2.xsd的complexType(“TVDSection”)中扩展Schema1.xsd的complexType(“tElementWithIDAndName”)。
当我尝试在Altova XMLSpy / oXygen xml编辑器中验证Schema2.xsd时,我收到以下错误:
错误: [Xerces] cos-nonambig:“http://www.mySchema.com/Generic/1”:element1和WC [## other:“http://www.mybasic.com/1”,“”](或来自其替换组的元素)违反“Unique Particle Attribution”。在针对此模式进行验证期间,将为这两个粒子创建歧义。
Schema1.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://www.mybasic.com/1"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
targetNamespace="http://www.mybasic.com/1"
elementFormDefault="qualified"
version="0.1">
<xs:complexType name="tElementWithIDAndName">
<xs:sequence>
<xs:element name="additionalName" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:any namespace="##other" processContents="strict" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required"/>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
</xs:schema>
Schema2.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://www.mySchema.com/Generic/1"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:myBasic="http://www.mybasic.com/1"
targetNamespace="http://www.mySchema.com/Generic/1"
elementFormDefault="qualified" version="0.1">
<xs:import namespace="http://www.mybasic.com/1" schemaLocation="schema.xsd"/>
<xs:element name="Element1" type="TVDSection"/>
<xs:complexType name="TVDSection">
<xs:complexContent>
<xs:extension base="myBasic:tElementWithIDAndName">
<xs:sequence>
<xs:element name="element1" type="xs:string" minOccurs="0" maxOccurs="unbounded">
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
我不知道这在何处/如何违反独特的粒子归属。 请帮我解决上述问题。
答案 0 :(得分:3)
您的内容模型可以解释为“任意数量的名为p:additionalName的元素,后跟任意数量的元素,前提是它们不在命名空间'p'中,后跟任意数量的名为q的元素:element1,”。现在,如果遇到aq:element1元素,验证器不知道是否将它放在第二组(任何数量的不在命名空间'p'中的元素)或第三组(任何名为q:element1的东西)中。因此含糊不清。
在XSD 1.1中,规范已经改变,因此在这种情况下,如果存在特定粒子和通配符粒子,两者都匹配,则始终优先选择特定粒子。因此,一种解决方案就是转移到XSD 1.1。如果你想继续使用XSD 1.0,你需要更改xs:any通配符,这样就会对允许元素的命名空间施加更多限制。