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

主宰稳场 提交于 2021-02-08 03:42:26

问题


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>

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/55480013/cvc-elt-1-cannot-find-the-declaration-of-element-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!