XML + Schema + Namespaces. No matching global declaration available for the validation root

namespacesschemaxml

What is the correct syntax when referring to schema when using namespaces?

Problem

Creating an XML document using a given schema.

Error


    .xml:9.20: Element '{http://example/buildings/1.0}old_buildings': No matching global declaration available for the validation root.
    oldbuildings.xml - invalid
    Problem

XML Document

<?xml version="1.0" encoding="UTF-8"?>

<buildings:old_buildings xmlns:buildings="http://example/buildings/1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://example/buildings/1.0 oldbuildings_schema.xsd">
    <building>
        <name>Name</name>
        <year_built era="BC">2000</year_built>
        <story>...<story>
    </building>
</buildings:old_buildings>

XSD Document


    <?xml version="1.0" encoding="UTF-8"?>

    <xs:schema targetNamespace="http://example/buildings/1.0/" 
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://example/buildings/1.0/"> <xs:element name="old_buildings"> <xs:complexType> <xs:sequence> <xs:element ref="building"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="building" type="buildingType"></xs:element> <xs:complexType name="buildingType"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="year_built" type="yearType"/> <xs:element name="story" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="yearType"> <xs:simpleContent> <xs:extension base="xs:positiveInteger"> <xs:attribute name="era" type="xs:string"/> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:schema>

Best Answer

In your xml file, try with

xmlns:buildings="http://example/buildings/1.0/"

with a / final, as in your xsd declaration : xs:schema targetNamespace="http://example/buildings/1.0/"

Related Topic