gpt4 book ai didi

java - cvc-elt.1.a : Cannot find the declaration of element 'people'

转载 作者:行者123 更新时间:2023-12-01 14:36:05 28 4
gpt4 key购买 nike

我正在尝试使用 XSD 验证我的 XML 文档。我尝试为所有内容提供 namespace ,包括默认 namespace 。但是,错误仍然存​​在。如果有人可以告诉我出了什么问题,我们将不胜感激

    <?xml version="1.0" encoding="UTF-8" ?>
<!-- <!DOCTYPE people SYSTEM "validator.dtd"> -->

<people
xmlns:cmuq="http://www.cmu.edu/ns/students"
xmlns="http://www.cmu.edy/ns/blank"
xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance"
xsi:schemaLocation="student.xsd"
>
<cmuq:student>
<name>John</name>
<course>Computer Technology</course>
<semester>6</semester>
<scheme>E</scheme>
</cmuq:student>

<cmuq:student>
<name>Foo</name>
<course>Industrial Electronics</course>
<semester>6</semester>
<scheme>E</scheme>
</cmuq:student>
</people>

XSD

<?xml version="1.0"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.cmu.edu/ns/blank"
targetNamespace="http://www.cmu.edu/ns/students">
<xs:element name="people">
<xs:complexType>
<xs:sequence>
<xs:element name="student" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="course" type="xs:string" />
<xs:element name="semester">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="1" />
<xs:enumeration value="2" />
<xs:enumeration value="3" />
<xs:enumeration value="4" />
<xs:enumeration value="5" />
<xs:enumeration value="6" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="scheme">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value = "E|C" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

请告诉我如何解决该错误

<小时/>

伊恩·罗伯茨回答后更新

XSD <schema>标签:

  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.cmu.edu/ns/blank"
targetNamespace="http://www.cmu.edu/ns/blank"
elementFormDefault="qualified">

XML 的根,<people>标签。

 <people
xmlns="http://www.cmu.edu/ns/blank"
xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.cmu.edu/ns/blank student.xsd">

它仍然没有验证。我现在放弃了添加 xmlns:cmuq 的想法但问题仍然存在。 >

最佳答案

您所拥有的架构在 http://www.cmu.edu/ns/students 命名空间(项目的目标命名空间)中声明了 people 元素。 schema)以及没有命名空间的所有嵌套元素(因为您不使用 elementFormDefault)。所以需要这样

<cmuq:people
xmlns:cmuq="http://www.cmu.edu/ns/students"
xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.cmu.edu/ns/students student.xsd"
>
<student>

另请注意,xsi:schemaLocation 需要是 namespaceUri schema 对的列表,而不仅仅是单个架构地址 - 此属性可以将不同的架构与每个命名空间。

关于java - cvc-elt.1.a : Cannot find the declaration of element 'people' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16477496/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com