我要拔掉头发,试图弄清为什么它无法验证。我不断收到错误
cvc-elt.1:找不到元素“ ret”的声明。 [13]
在出现schemaLocation错误之前,它告诉我URI的长度必须相同或类似,但我通过使schemaLocation,target和targetNamespace相同来解决了这一问题。
但是它仍然找不到我的“ ret”元素声明,也找不到原因。现在我不太擅长命名空间,我对它们以及其他所有东西都不了解。
我们将非常感谢您提供帮助以找出解决此错误的方法。
哦,我的.xsd文件也命名为“ ret”,所以我的第一个元素也是如此。我不认为这会引起问题,但不会让任何人感到困惑。这只是我的要求。
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:My.Namespace"
xmlns:target="urn:My.Namespace ret.xsd"
elementFormDefault="qualified"
>
<xs:element name="ret">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="feed" />
<xs:element ref="doc-copyright" />
</xs:sequence>
<xs:attribute fixed="1.0" name="version" type="xs:string" />
<xs:attribute name="date" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
这是我的.xsd文件的一部分
<?xml version="1.0" encoding="UTF-8"?>
<ret
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.w3schools.com"
xsi:schemaLocation="urn:My.Namespace ret.xsd">
</ret>
这是xml文件中不会验证的部分。如果我需要发布更多信息,我可以。虽然很长。我想知道是否是因为My.Namespace不是有效的名称空间?我只是不明白。
答案 0 :(得分:0)
在您的模式中,您说过,当拥有urn:My.Namespace
时,元素将绑定到@targetNamespace="urn:My.Namespace"
。
但是您的实例XML文档具有绑定到http://www.w3schools.com
名称空间的“ ret”元素。
为使其在架构上有效,必须将其绑定到urn:Ny.Namespace
命名空间。
将其更改为:
<ret
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:My.Namespace"
xsi:schemaLocation="urn:My.Namespace ret.xsd">
</ret>
,然后处理其他验证问题(无提要,文档版权,@ version或@date)