【发布时间】:2022-02-08 03:54:17
【问题描述】:
我对 XML 很陌生,尽管我已经管理得很好,但我现在被这个关于 XML Schema 的棘手情况困住了。您可以在下面看到我的 XML 文档代码及其各自的 Schema 代码。首先这里是我的 XML 文档代码。
<?xml version="1.0" encoding="UTF-8"?>
<Cars
xmlns="http://www.verkkokauppa.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema"
xsi:schemaLocation="http://www.verkkokauppa.com 4Schema.xsd">
<Car>
<Brand>BMW</Brand>
<Model>535d</Model>
<Gear>Automatic</Gear>
<Year>2007</Year>
<Info>It's a german.</Info>
</Car>
</Cars>
下面你可以看到我的代表性架构代码
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.verkkokauppa.com" xmlns="http://www.verkkokauppa.com" elementFormDefault = "qualified"> <xsd:element name = "Brand" type = "xsd:string"/> <xsd:element name = "Model" type = "xsd:string"/> <xsd:element name = "Gear" type = "xsd:string"/> <xsd:element name = "Year" type = "xsd:int"/> <xsd:element name = "Information" type = "xsd:string"/> <xsd:complexType name = "CarType"> <xsd:sequence> <xsd:element ref = "Brand"/> <xsd:element ref = "Model"/> <xsd:element ref = "Gear"/> <xsd:element ref = "Year"/> <xsd:element ref = "Information" minOccurs = "0" maxOccurs = "1" /> </xsd:sequence> </xsd:complexType> <xsd:element name = "Cars"> <xsd:complexType> <xsd:sequence> <xsd:element name = "Car" type = "CarType" maxOccurs = "unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>
现在,每当我尝试验证我的 XML 文档代码时,都会出现错误: “cvc-elt.1:找不到元素‘汽车’的声明。[6]”
我认为这与作为我的根元素的 Cars 元素上的命名空间问题有关,但我真的不确定。
如果有人可以指导我,我将不胜感激。
【问题讨论】: