【发布时间】:2019-11-05 11:23:39
【问题描述】:
我有以下“imp.xsd”:
<xsd:schema targetNamespace="http://imported"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Imported" type="xsd:string"/>
</xsd:schema>
从“incl.xsd”导入:
<xsd:schema targetNamespace="http://main"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://imported" schemaLocation="file:///C:/.../imp.xsd"/>
<xsd:element name="Included" type="xsd:string"/>
</xsd:schema>
又包含来自“main.xsd”:
<xsd:schema targetNamespace="http://main"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:include schemaLocation="file:///C:/.../incl.xsd"/>
<xsd:complexType name="dummy">
<xsd:sequence xmlns:impt="http://imported" xmlns:incl="http://main">
<xsd:element ref="incl:Included"/>
<xsd:element ref="impt:Imported"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
问题:“main.xsd”是一个有效的 xml 架构文档吗?
当使用 xmllint 解析器(或来自 python lxml 库,而后者又使用 xmllint)进行验证时,我收到以下错误:
元素'{http://www.w3.org/2001/XMLSchema}元素',属性'ref': 从此模式中引用命名空间中的组件 'http://imported' 是不允许的,因为导入时没有指明 陈述。 WXS 架构 main.xsd 编译失败
但是,另一个 (IBM) 解析器接受此 XSD 时没有任何投诉。
据我了解 xsd:include,它应该表现得好像整个包含的 XSD 都内联到主文档中。所以,在我看来,“main.xsd”应该是有效的。是吗?
编辑:我正在尝试xmllint,当我添加该行时
<xsd:import namespace="http://imported" schemaLocation="file:///C:/.../imp.xsd"/>
进入“main.xsd”,xmllint 接受该模式。但是,当我在省略 file:/// 的同时添加同一行时,会收到以下警告:
元素“{http://www.w3.org/2001/XMLSchema}import”:跳过导入 位于命名空间的“C:/.../imported.xsd”的架构 'http://imported',因为这个命名空间已经用 架构位于 'file:///V:/.../imported.xsd'。
因此我推断原始的“main.xsd”是有效的,这是xmllint 中的一个错误。
【问题讨论】:
标签: xsd lxml libxml2 xmllint xsd-1.1