我创建了以下 XSD(使用 Eclipse):
<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="http://www.example.com" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.example.com">
<element name="Make">
<complexType>
<sequence>
<element name="Scope"></element>
</sequence>
</complexType>
</element>
</schema>
并使用这个简单的 XML 进行验证
<?xml version="1.0"?>
<Make xmlns="http://www.example.com">
<Scope>
</Scope>
</Make>
给出:
xmllint.exe --noout --schema sources.xsd sources.xml
sources.xml:3: element Scope: Schemas validity error : Element '{http://www.example.com}Scope': This element is not expected. Expected is ( Scope ).
sources.xml fails to validate
在我看来,这一定是正确的:XML 文件位于命名空间http://www.example.com中(验证器也是这样说的)。
对于 XSD,我将默认命名空间设置为 XSD 模式(这是 Eclipse 所做的,所以它应该是正确的!)并且我给出了正确的 targetNamespace。我也尝试使用
<element name="tnd:Scope" />
但是,这也不起作用。
这是 xmllint 中的错误还是问题出在哪里?
问候 divB