我有一个(相当)简单的 XML 和相应的架构文件。当我尝试对另一个进行验证时,netbeans 会吐出以下错误消息:
文档类型声明包含或指向的标记声明必须格式正确。[2]
这表明我的 Schema 文件本身格式不正确。但是,当我验证我的架构文件时,没有错误。谁能发现我的错误(或者以其他方式教育我关于我不理解的内容)?
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>
和 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>
我对 XML 有点陌生。虽然我熟悉一般语法和功能,但我仍然觉得标题部分非常混乱。