I have a (reasonably) simple XML and corresponding Schema file. When I attempt to validate one against the other, netbeans spits out the following error message:
我有一个(合理的)简单的XML和相应的模式文件。当我尝试对其中一个进行验证时,netbeans会输出以下错误消息:
The markup declarations contained or pointed to by the document type declaration must be well-formed. [2]
文档类型声明中包含或指向的标记声明必须格式良好。[2]
This suggests that my Schema file itself is not well formed. However when I validate my Schema file, there is no error. Can anyone spot my mistake (Or otherwise educate me as to what I am not understanding)?
这说明我的模式文件本身并没有很好地形成。但是,当我验证我的模式文件时,没有错误。谁能指出我的错误(或者教育我不理解的东西)?
XML:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map SYSTEM "maps.xsd">
<map xmlns="http://example.com/sample" id="testMap" name="Test Map">
<transferRoom id="start" name="Start" posX="0" posY="0">
<type>transfer</type>
<description>The starting room for the game.</description>
<transferID>testMap.testingGrounds</transferID>
<passageNorth>false</passageNorth>
<passageEast>false</passageEast>
<passageSouth>true</passageSouth>
<passageWest>false</passageWest>
</transferRoom>
</map>
and XSD (called maps.xsd):
和XSD(称为maps.xsd):
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://example.com/sample" elementFormDefault="qualified">
<xs:element name="map">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" ref="transferRoom"/>
<xs:element maxOccurs="unbounded" ref="room"/>
</xs:sequence>
<xs:attribute name="name" use="required"/>
<xs:attribute name="id" use="required" type="xs:ID"/>
</xs:complexType>
</xs:element>
<xs:element name="transferRoom">
<xs:complexType>
<xs:sequence>
<xs:element ref="type"/>
<xs:element ref="description"/>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="container"/>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="enemy"/>
<xs:element ref="transferID"/>
<xs:element ref="passageNorth"/>
<xs:element ref="passageEast"/>
<xs:element ref="passageSouth"/>
<xs:element ref="passageWest"/>
</xs:sequence>
<xs:attribute name="name" use="required"/>
<xs:attribute name="id" use="required" type="xs:ID"/>
<xs:attribute name="posX" use="required"/>
<xs:attribute name="posY" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="type" type="xs:string"/>
<xs:element name="description" type="xs:string"/>
<xs:element name="container">
<xs:complexType>
<xs:sequence>
<xs:element ref="name"/>
<xs:element ref="description"/>
<xs:element ref="level"/>
</xs:sequence>
<xs:attribute name="locked" default="false">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="true"/>
<xs:enumeration value="false"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="name" type="xs:string"/>
<xs:element name="enemy">
<xs:complexType>
<xs:sequence>
<xs:element ref="type"/>
<xs:element ref="description"/>
<xs:element ref="level"/>
</xs:sequence>
<xs:attribute name="name" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="level" type="xs:string"/>
<xs:element name="transferID" type="xs:string"/>
<xs:element name="passageNorth" type="xs:boolean"/>
<xs:element name="passageEast" type="xs:boolean"/>
<xs:element name="passageSouth" type="xs:boolean"/>
<xs:element name="passageWest" type="xs:boolean"/>
<xs:element name="room">
<xs:complexType>
<xs:sequence>
<xs:element ref="type"/>
<xs:element ref="description"/>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="container"/>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="enemy"/>
<xs:element ref="passageNorth"/>
<xs:element ref="passageEast"/>
<xs:element ref="passageSouth"/>
<xs:element ref="passageWest"/>
</xs:sequence>
<xs:attribute name="name" use="required"/>
<xs:attribute name="id" use="required" type="xs:ID"/>
<xs:attribute name="posX" use="required"/>
<xs:attribute name="posY" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
I am somewhat new to XML. While I am familiar with the general syntax and function, I still find the header section very confusing.
我对XML有点陌生。虽然我熟悉一般的语法和函数,但我仍然觉得标题部分非常混乱。
2 个解决方案
#1
3
The doctype element is used for association with DTD, not XSD.
doctype元素用于与DTD的关联,而不是XSD。
use xsi:schemaLocation="maps.xsd"
on the root element instead.
使用xsi:schemaLocation = "地图。而是根元素上的xsd。
#2
2
More precisely, declare xsi namespace and then use it to mark your schema, like this:
更准确地说,声明xsi名称空间,然后使用它来标记您的模式,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<map xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://example.com/sample" id="testMap" name="Test Map"
xsi:schemaLocation="maps.xsd">
...
#1
3
The doctype element is used for association with DTD, not XSD.
doctype元素用于与DTD的关联,而不是XSD。
use xsi:schemaLocation="maps.xsd"
on the root element instead.
使用xsi:schemaLocation = "地图。而是根元素上的xsd。
#2
2
More precisely, declare xsi namespace and then use it to mark your schema, like this:
更准确地说,声明xsi名称空间,然后使用它来标记您的模式,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<map xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://example.com/sample" id="testMap" name="Test Map"
xsi:schemaLocation="maps.xsd">
...