xml 示例不起作用 - 不断出现相同的错误 "xsi:noNamespaceSchemaLocation = "hello.xsd" >"

xml examples not working- keep getting same error "xsi:noNamespaceSchemaLocation = "hello.xsd" >"

这是 "hello.xml" 文档。我在 Mac 上使用 jedit,我正在遵循本书中名为 ineasysteps 的示例。我不确定我的代码是错误的还是我的编辑器还是什么?我尝试使用 sublimetext 编辑器,但那是一场噩梦,因为 xml 文件似乎没有读取 dtd 文件。感谢您的帮助

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

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

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


<msg>Hello World!</msg>

</doc>


 hello.xsd-----------------

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

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

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


 <!-- DECLARE ELEMENTS. -->
<xsd:element name="doc" type="docType"/>
<xsd:element name="msg" type="xsd:string"/>

<!-- DEFINE STRUCTURE. -->
<xsd:complexType name="docType">
<xsd:sequence>
    <xsd:element ref="msg"/>
</xsd:sequence>
</xsd:complexType>

</xsd:schema

在您的 XML 中,名称空间 uri 不正确。

而不是:

http://www.w3.org/2001/XMLSchemaInstance

应该是:

http://www.w3.org/2001/XMLSchema-instance

示例...

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

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

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

    <msg>Hello World!</msg>

</doc>