2016-03-08 111 views
1

我对XML非常陌生,现在已准备好Ineasysteps。 我一直从解析器得到相同的问题,他说错误:元素“xsd:schema”的前缀“xsd”未绑定

5:The prefix "xsd" for element "xsd:schema" is not bound.

这是的hello.xml:

<?xml version = "1.0" encoding = "UTF-8" ?> 

<!-- XML in easy steps - Page 82. --> 

<doc xmlns:xsi= 
"http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation = "hello.xsd" > 

<msg>Hello World</msg> 

</doc> 

这里是hello.xsd DOC

<?xml version="1.0" encoding = "UTF-8" ?> 

<!-- XML in easy steps - Page 84. --> 

<xsd:schema> 

<!-- DECLARE ELEMENTS. --> 

<!-- Simple types. --> 
<xsd:element name="msg" type="xsd:string"/> 

<!-- Complex types. --> 
<xsd:element name="doc" type="docType"/> 

<!-- DEFINE STRUCTURE. --> 

<xsd:complexType name="docType"> 
<xsd:sequence> 
    <xsd:element ref="msg"/> 
</xsd:sequence> 
</xsd:complexType 

回答

2

命名空间前缀。因为在使用前必须定义xsd。这甚至适用于通常用于XML模式组件(XSD)的着名的xsd(或xs)前缀。

要消除错误,通过添加

xmlns:xsd="http://www.w3.org/2001/XMLSchema" 

xsd:schema根元素这样定义xsd命名空间前缀:

<?xml version="1.0" encoding = "UTF-8" ?> 
<!-- XML in easy steps - Page 84. --> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 

    <!-- DECLARE ELEMENTS. --> 

    <!-- Simple types. --> 
    <xsd:element name="msg" type="xsd:string"/> 

    <!-- Complex types. --> 
    <xsd:element name="doc" type="docType"/> 

    <!-- DEFINE STRUCTURE. --> 

    <xsd:complexType name="docType"> 
    <xsd:sequence> 
     <xsd:element ref="msg"/> 
    </xsd:sequence> 
    </xsd:complexType> 
</xsd:schema> 
+0

谢谢你,我不知道你是怎么到答案,但它像一个魅力。再次感谢!! –

+0

回答更新以在修复之前添加原理以帮助您查看“我如何得到该答案”。 – kjhughes

相关问题