2

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>
Sukhinderpal Mann
  • 744
  • 1
  • 10
  • 23

2 Answers2

2

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.

Daniel Haley
  • 51,389
  • 6
  • 69
  • 95
  • I tried doing the same and it still doesn't work. Even tried validating my XML against my XSD online. Just for information, my XSD is on my local storage. – Sukhinderpal Mann Apr 02 '19 at 17:17
  • @S.Mann - For my testing, I placed the XML file and the XSD in the same location. I then updated the XML file with the fixed namespace and changed the xsi:schemaLocation to `xsi:schemaLocation="https://www.w3schools.com/xml car_designer.xsd"` (I removed `{FULL_PATH}/`.). It validated in oXygen fine. – Daniel Haley Apr 02 '19 at 17:20
  • I just checked it online as well. It worked! But with Netbeans quick validation it fails, odd. Thanks anyway! – Sukhinderpal Mann Apr 02 '19 at 17:24
  • The namespace in xsi:schemaLocation is different again: `https://www.w3schools.com/xml` – Michael Kay Apr 02 '19 at 21:19
1

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.

Bizi
  • 69
  • 1
  • 8