【发布时间】:2013-10-14 01:00:42
【问题描述】:
我制作了一个 XML 文件和 XML Schema 用于验证。我试过了,但它给了我一些错误。
XML 文件格式正确,XML Schema 格式也正确。但是当我尝试使用 XSD 验证 XML 时,它给了我一些错误。 图片:LINK
当我将 XSD 中的第 2 行更改为:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3schools.com">
它给了我另一个错误图片:LINK
请你帮我看看我哪里出错了?
2013-10-14 10:57 更新(复制自答案):
对不起,我有点过度劳累,我没有意识到我缺少书标签。但是,它仍然给我一个错误。我仍然做错了什么?我附上了我的 XML 和 XML 模式。
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3schools.com">
<xs:element name="library">
<xs:complexType>
<xs:sequence>
<xs:element name="book"/>
<xs:element name="book_id" type="xs:integer"/>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
<xs:element name="count" type="xs:integer"/>
<xs:element name="genre" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml version="1.0"?>
<library>
<book>
<book_id>5</book_id>
<title>Sokak</title>
<author>Tony</author>
<count>6</count>
<genre>epic</genre>
</book>
<book>
<book_id>13</book_id>
<title>Kucharka</title>
<author>Fiona</author>
<count>8</count>
<genre>Hobby</genre>
</book>
</library>
【问题讨论】:
-
xsd 中没有 book 元素
-
我认为您的架构不能准确地反映结构。图书馆包含称为 book 的复杂类型的序列,其中包含书籍 ID 和标题等元素。这不是你的架构所说的。
标签: xml validation xsd w3c-validation