cvc-elt.1:找不到元素'data'的声明



这些是我简单的XSD和XML文件,我一直得到cvc-elt.1作为"data"节点。

这是 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>

这是 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>

问题是 XML 文件中的默认命名空间是 http://www.w3schools.com ,但架构中的 targetNamespace 是 https://www.w3schools.com

请注意 uri 中httphttps之间的差异。如果将 XML 中的命名空间更改为 https ( xmlns="https://www.w3schools.com" (,它应该可以工作。

我只是注意到,有时,即使一切正常,也只是使用的 IDE 显示此错误。

在我的情况下,我所做的是进入一个声明正常的文件,复制标题并用错误替换标题,现在一切都可以了。

最新更新