【问题标题】:"Cannot find the declaration of element" validating with XSD“找不到元素的声明”使用 XSD 进行验证
【发布时间】:2020-11-03 07:15:47
【问题描述】:

我是一个完整的 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: 找不到元素'note'.xml 的声明

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

【问题讨论】:

    标签: xml xsd xsd-validation xml-validation


    【解决方案1】:

    改变

    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" 匹配。

    另见

    【讨论】:

      猜你喜欢
      • 2012-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多