我将发布两个示例,一个验证,另一个不验证。我有兴趣了解为什么第二个示例不起作用,因为它们非常相似。
例1
(验证)
XSD:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<xsd:element name="root" type="BBB"/>
<xsd:complexType name="AAA">
<xsd:choice maxOccurs="2">
<xsd:element name="x" type="xsd:string"/>
<xsd:element name="y" type="xsd:string"/>
</xsd:choice>
</xsd:complexType>
<xsd:complexType name="BBB">
<xsd:complexContent>
<xsd:extension base="AAA"/>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
XML:
<root xsi:noNamespaceSchemaLocation="incorrect.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<x>1</x>
<y>1</y>
</root>
例2
(不验证)
XSD:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<xsd:element name="root" type="BBB"/>
<xsd:complexType name="AAA">
<xsd:choice maxOccurs="2">
<xsd:element name="x" type="xsd:string"/>
<xsd:element name="y" type="xsd:string"/>
</xsd:choice>
</xsd:complexType>
<xsd:complexType name="BBB">
<xsd:complexContent>
<xsd:extension base="AAA">
<xsd:choice>
<xsd:element name="z" type="xsd:string"/>
</xsd:choice>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
XML:
(与例1相同)
<根xsi:nonamespaceSchemaLocation=“incorrect.xsd”xmlns=“”xmlns:xsi=“http://www.w3.org/2001/xmlschema-instance”>
<x>1</x>
<Y>1</Y>
&根/根;
为了节省对xsd运行diff的时间,唯一的区别是在第二个示例中,复杂类型bbb具有
<choice>
XMLLNT
下面是关于示例2的内容:
$xmllint--noout--schema example2.xsd example2.xml
示例2.xml:3:element y:schemas validity error:element'y':不需要此元素。应为(z)。
example2.xml无法验证
基于以下内容的示例
http://www.zvon.org/xxl/XMLSchemaTutorial/Output/ser_ext_patterns_st1.html