Question

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:

The markup declarations contained or pointed to by the document type declaration must be well-formed. [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 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):

<?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.

Was it helpful?

Solution

The doctype element is used for association with DTD, not XSD.

use xsi:schemaLocation="maps.xsd" on the root element instead.

OTHER TIPS

More precisely, declare xsi namespace and then use it to mark your schema, like this:

<?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">
...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top