【发布时间】:2012-05-13 18:36:28
【问题描述】:
我创建了以下 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
【问题讨论】:
-
错字?
tnd:Scope应该是tns:Scope
标签: xml xsd schema validation xmllint