首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XML模式,XML错误

XML模式,XML错误
EN

Stack Overflow用户
提问于 2013-10-14 14:21:58
回答 1查看 119关注 0票数 0

你好,我对有问题。XML格式良好,也是如此.但是,当我尝试用XML验证XML时,出现了一些错误。我在做什么坏事?我已经附加了我的XML和XML模式。谢谢你的帮助。

我使用的是:http://www.utilities-online.info/xsdvalidation/发生了错误:图图

代码语言:javascript
复制
<?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>

代码语言:javascript
复制
<?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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-14 14:31:44

首先,模式定义了文档中没有使用的targetNamespace,即http://www.w3schools.com。尝试添加更改文档如下:

代码语言:javascript
复制
<library xmlns="http://www.w3schools.com">
    <!-- ... -->
</library>

其次,模式定义元素序列,而文档包含嵌套结构。如果需要嵌套结构,请调整模式,如本例所示:

代码语言:javascript
复制
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.w3schools.com"
    xmlns:w3s="http://www.w3schools.com"
    elementFormDefault="qualified">

<xs:complexType name="bookType">
    <xs:sequence>
        <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:complexType name="libraryType">
    <xs:sequence maxOccurs="unbounded">
        <xs:element name="book" type="w3s:bookType" />
    </xs:sequence>
</xs:complexType>

<xs:element name="library" type="w3s:libraryType" />

</xs:schema>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19362429

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档