XML + 架构 + 命名空间。没有可用于验证根的匹配全局声明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15174174/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XML + Schema + Namespaces. No matching global declaration available for the validation root
提问by user2126173
What is the correct syntax when referring to schema when using namespaces?
使用命名空间时引用模式的正确语法是什么?
Problem
问题
Creating an XML document using a given schema.
使用给定的模式创建 XML 文档。
Error
错误
.xml:9.20: Element '{http://example/buildings/1.0}old_buildings': No matching global declaration available for the validation root.
oldbuildings.xml - invalid
Problem
XML Document
XML 文件
<?xml version="1.0" encoding="UTF-8"?>
<buildings:old_buildings xmlns:buildings="http://example/buildings/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://example/buildings/1.0 oldbuildings_schema.xsd">
<building>
<name>Name</name>
<year_built era="BC">2000</year_built>
<story>...<story>
</building>
</buildings:old_buildings>
XSD Document
XSD 文件
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://example/buildings/1.0/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://example/buildings/1.0/">
<xs:element name="old_buildings">
<xs:complexType>
<xs:sequence>
<xs:element ref="building"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="building" type="buildingType"></xs:element>
<xs:complexType name="buildingType">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="year_built" type="yearType"/>
<xs:element name="story" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="yearType">
<xs:simpleContent>
<xs:extension base="xs:positiveInteger">
<xs:attribute name="era" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>
回答by Istao
In your xml file, try with
在您的 xml 文件中,尝试使用
xmlns:buildings="http://example/buildings/1.0/"
xmlns:buildings="http://example/buildings/1.0/"
with a / final, as in your xsd declaration : xs:schema targetNamespace="http://example/buildings/1.0/"
带有 / final,就像在您的 xsd 声明中一样: xs:schema targetNamespace="http://example/buildings/1.0/"

