"Cannot find the declaration of element" 使用 XSD 验证

"Cannot find the declaration of element" validating with XSD

我是 XML 的完全初学者,我正在尝试学习 XML Schema。我有这两个文件:

note.xml

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

<note
 xmlns="https://www.w3schools.com"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xsi:schemaLocation="https://www.w3schools.com/xml note.xsd">

   <to>Tove</to>
   <from>Jani</from>
   <heading>Reminder</heading>
   <body>Don't forget me this weekend!</body>


</note>

note.xsd

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

<xs:schema 
xmlns:xs="http://www.w3.org/2001/XMLSchema"          targetNamespace="https://www.w3schools.com"
xmlns = "https://www.w3schools.com"
elementFormDefault="qualified">

  <xs:element name="note">
    <xs:complexType>
      <xs:sequence>
        <xs:element name = "to" type ="xs:string"/>
        <xs:element name = "from" type = "xs:string"/>
        <xs:element name = "heading" type = "xs:string"/>
        <xs:element name = "body" type = "xs:string"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>


</xs:schema>

在 note.xml 我得到错误

cvc-elt.1.a: Cannot find the declaration of element 'note'.xml

在我的根笔记元素上。我在这里看过其他帖子,但对于更复杂的解决方案,但我是一个完全的初学者,什么都不懂。如果您能指导我解决这个错误,我将不胜感激。

改变

xsi:schemaLocation="https://www.w3schools.com/xml note.xsd"

xsi:schemaLocation="https://www.w3schools.com note.xsd"

以便命名空间 URL 匹配 XML 文档中的 xmlns="https://www.w3schools.com" 和 XSD.

中的 targetNamespace="https://www.w3schools.com"

另见

  • How to link XML to XSD using schemaLocation or noNamespaceSchemaLocation?
  • How to reference a local XML Schema file correctly?