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:找不到元素'note'.xml的声明

在我的根注释元素上。我在这里看到过其他文章,但需要更复杂的解决方案,但我是一个完整的初学者,不了解任何内容。如果您能指导我解决错误,我将不胜感激。

解决方法

更改

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

xmlns="https://www.w3schools.com"

使名称空间URL与XML文档中的targetNamespace="https://www.w3schools.com"和XSD中的def fix_digits(val): if val[:4] in ('3372','2277'): return val[:4] return val # Here you'll need the actual code to read your CSV file for row in csv_file: # Assuming your value is in the 6'th column row[5] = fix_digits(row[5]) 相匹配。

另请参见

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...