如何解决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])
相匹配。
另请参见
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。