这些是我的简单 XSD 和 XML 文件,我不断获取“数据”节点的 cvc-elt.1。
这是 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 中 http
和 https
之间的区别。如果将 XML 中的命名空间更改为 https (xmlns="https://www.w3schools.com"
),它应该可以工作。
关于xml - cvc-elt.1 : Cannot find the declaration of element 'data' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55480013/