Sukhinderpal Mann
Sukhinderpal Mann

Reputation: 884

cvc-elt.1: Cannot find the declaration of element 'data'

These are my simple XSD and XML files, I keep getting cvc-elt.1 for the "data" node.

Here is the XML

<?xml version="1.0" encoding="UTF-8" ?>
<data xmlns="http://www.w3schools.com" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="https://www.w3schools.com/xml {FULL_PATH}/car_designer.xsd">
    <car_designer id="1" designer_name="A C Bertelli"/>
    <car_designer id="2" designer_name="Adam Ty Dean Smith"/>
</data>

Here is the XSD

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="https://www.w3schools.com"
           xmlns="https://www.w3schools.com"
           elementFormDefault="qualified">
    <xs:element name="data">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="car_designer" maxOccurs="unbounded">
                    <xs:complexType>
                        <xs:attribute name="id" type="xs:int"></xs:attribute>
                        <xs:attribute name="designer_name" type="xs:string"></xs:attribute>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

Upvotes: 2

Views: 3936

Answers (2)

Bizi
Bizi

Reputation: 69

i just notice that at times, it is just the IDE used that shows this errors even when everything is ok.

What i did in my case was to go into a file where declaration is ok, copy the header and replaced the one with the error, now it's all ok.

Upvotes: 1

Daniel Haley
Daniel Haley

Reputation: 52858

The problem is that the default namespace in the XML file is http://www.w3schools.com, but the targetNamespace in the schema is https://www.w3schools.com.

Notice the difference between http and https in the uri. If you change the namespace in the XML to https (xmlns="https://www.w3schools.com"), it should work.

Upvotes: 3

Related Questions