XML模式,XML错误
您好,我对XML-XML模式有问题。XML格式良好,XML模式也是如此。但当我尝试用XML模式验证XML时,出现了一些错误。我做了什么坏事?我已经附上了我的XML和XML模式。谢谢你的帮助 我正在使用: 出现以下错误:XML模式,XML错误,xml,validation,Xml,Validation,您好,我对XML-XML模式有问题。XML格式良好,XML模式也是如此。但当我尝试用XML模式验证XML时,出现了一些错误。我做了什么坏事?我已经附上了我的XML和XML模式。谢谢你的帮助 我正在使用: 出现以下错误: 5. 索卡 托尼 6. 史诗 13 库查尔卡 Fiona 8. 爱好 首先,模式定义了文档中未使用的targetNamespace,即http://www.w3schools.com。尝试添加或更改您的文档,如: <library xmlns="http://www
5.
索卡
托尼
6.
史诗
13
库查尔卡
Fiona
8.
爱好
首先,模式定义了文档中未使用的targetNamespace
,即http://www.w3schools.com
。尝试添加或更改您的文档,如:
<library xmlns="http://www.w3schools.com">
<!-- ... -->
</library>
其次,模式定义元素序列,而文档包含嵌套结构。如果需要嵌套结构,请调整模式,如本例所示:
<?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>
您可能已经发布了错误:无效。错误-第2行,12:org.xml.sax.SAXParseException;行号:2;列数:12;cvc elt.1:找不到元素“library”的声明。
<library xmlns="http://www.w3schools.com">
<!-- ... -->
</library>
<?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>