Xml 找不到元素';汽车&x27;
第一次在这里发布。我在使用某些XLM和XSD时遇到困难。我不断得到以下错误: 找不到元素“car”的声明。[13] 我已经搜索了该网站寻求帮助,但如果不添加更多错误,我似乎无法取得任何进展(我想这可能是问题所在)。我将感谢所有的帮助 XML的一部分:Xml 找不到元素';汽车&x27;,xml,xsd,xsd-validation,xml-validation,Xml,Xsd,Xsd Validation,Xml Validation,第一次在这里发布。我在使用某些XLM和XSD时遇到困难。我不断得到以下错误: 找不到元素“car”的声明。[13] 我已经搜索了该网站寻求帮助,但如果不添加更多错误,我似乎无法取得任何进展(我想这可能是问题所在)。我将感谢所有的帮助 XML的一部分: <car xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="carcatalog.xsd"> <mak
<car
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="carcatalog.xsd">
<make><h2>Make: </h2>Honda</make>
<model><h2>Model: </h2>Accord</model>
<year><h2>Year: </h2>2020</year>
<color><h2>Color: </h2>Red</color>
<engine>
<number_of_cylinders><h2>Number of Cylinders: </h2>4</number_of_cylinders>
<fuel_system><h2>Fuel System: </h2>Fuel Injected</fuel_system>
</engine>
<number_of_doors><h2>Doors: </h2>4</number_of_doors>
<transmission_type><h2>Transmission: </h2>Automatic</transmission_type>
<accessories>
<radio><h2>Radio: </h2>Yes</radio>
<air_conditioner><h2>Air Conditioner: </h2>Yes</air_conditioner>
<power_windows><h2>Power Windows: </h2>No</power_windows>
<power_steering><h2>Power Steering: </h2>Yes</power_steering>
<power_brakes><h2>Power Brakes: </h2>Yes</power_brakes>
</accessories>
<h1></h1>
<make><h2>Make: </h2>Chevrolet</make>
<model><h2>Model: </h2>Corvette</model>
<year><h2>Year: </h2>2020</year>
<color><h2>Color: </h2>Blue</color>
<engine>
<number_of_cylinders><h2>Number of Cylinders: </h2>8</number_of_cylinders>
<fuel_system><h2>Fuel System: </h2>Fuel Injected</fuel_system>
</engine>
<number_of_doors><h2>Doors: </h2>2</number_of_doors>
<transmission_type><h2>Transmission: </h2>Manual</transmission_type>
<accessories>
<radio><h2>Radio: </h2>Yes</radio>
<air_conditioner><h2>Air Conditioner: </h2>Yes</air_conditioner>
<power_windows><h2>Power Windows: </h2>Yes</power_windows>
<power_steering><h2>Power Steering: </h2>Yes</power_steering>
<power_brakes><h2>Power Brakes: </h2>Yes</power_brakes>
</accessories>
<h1></h1>
<make><h2>Make: </h2>Toyota</make>
<model><h2>Model: </h2>Tacoma</model>
<year><h2>Year: </h2>2017</year>
<color><h2>Color: </h2>Cement</color>
<engine>
<number_of_cylinders><h2>Number of Cylinders: </h2>6</number_of_cylinders>
<fuel_system><h2>Fuel System: </h2>Fuel Injected</fuel_system>
</engine>
<number_of_doors><h2>Doors: </h2>4</number_of_doors>
<transmission_type><h2>Transmission: </h2>Automatic</transmission_type>
<accessories>
<radio><h2>Radio: </h2>Yes</radio>
<air_conditioner><h2>Air Conditioner: </h2>Yes</air_conditioner>
<power_windows><h2>Power Windows: </h2>Yes</power_windows>
<power_steering><h2>Power Steering: </h2>Yes</power_steering>
<power_brakes><h2>Power Brakes: </h2>Yes</power_brakes>
</accessories>
</car>
品牌:本田
型号:雅阁
年份:2020年
颜色:红色
气缸数:4
燃油系统:燃油喷射
门:4
变速器:自动
收音机:是的
空调:是的
电动车窗:没有
动力转向:是的
电动刹车:是的
品牌:雪佛兰
型号:克尔维特
年份:2020年
颜色:蓝色
气缸数:8
燃油系统:燃油喷射
门:2
变速器:手动
收音机:是的
空调:是的
电动车窗:是的
动力转向:是的
电动刹车:是的
品牌:丰田
型号:塔科马
年份:2017年
颜色:水泥
气缸数:6
燃油系统:燃油喷射
门:4
变速器:自动
收音机:是的
空调:是的
电动车窗:是的
动力转向:是的
电动刹车:是的
XSD的一部分:
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="catalog">
<xs:complexType>
<xs:sequence>
<xs:element name = "car" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name = "make" type="xs:string"/>
<xs:element name = "model" type="xs:string"/>
<xs:element name = "year" type="xs:positiveInteger"/>
<xs:element name = "color" type="xs:string"/>
<xs:element name="engine">
<xs:complexType>
<xs:sequence>
<xs:element name="number_of_cylinders" type="xs:positiveInteger"/>
<xs:element name="fuel_system">
<xs:complexType>
<xs:sequence>
<xs:choice>
<xs:element name="fuel_injected"/>
<xs:element name="carbureted"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name = "number_of_doors" type="xs:positiveInteger"/>
<xs:element name = "transmission_type" type="xs:string"/>
<xs:element name = "accessories">
<xs:complexType>
<xs:sequence>
<xs:element name = "radio" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="yes"/>
<xs:enumeration value="no"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name = "air_conditioner" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="yes"/>
<xs:enumeration value="no"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name = "power_windows" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="yes"/>
<xs:enumeration value="no"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name = "power_steering" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="yes"/>
<xs:enumeration value="no"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name = "power_brakes" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="yes"/>
<xs:enumeration value="no"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
错误原因
在您的示例中,错误的原因是XML中的根元素car
,在XSD中没有顶级声明
这一问题的补救办法
将car
的声明移动到XSD中的顶层,或者使用catalog
在XML中包装car
,该目录在顶层定义并在其内容模型中包含car
如果您选择将car
的声明移动到XSD中的顶层,您可以通过
而不是xs:element/@name
错误的其他原因
在验证期间找不到元素还有许多其他原因。另见:
car
元素似乎位于某个(不完整的)命名空间中,但它只是目录的子元素。在你提供答案之前,你能得到的最具体的答案是那些在重复链接中提供的答案。(因为他们(几乎)涵盖了这一领域的所有内容,他们可能也涵盖了您未指定的案例。)对不起大家!我发布了代码,希望能给出一个更完整的答案。是的@kjhughes我确实感觉到我的答案就在那里,但我刚刚从一个初学者的角度开始挣扎,到目前为止,我已经用了大量的过度积累来帮助解决我的问题-我就是无法克服这个问题。我重新打开了这个问题,并在下面给出了答案。请回答或跟进你对你的问题的感觉。谢谢。@djchach:不客气。如果有帮助,请回答这个问题。谢谢(如果你愿意的话,那么你也会有足够的声誉来提高投票率。”——)
<xs:element ref="car" ... >