gpt4 book ai didi

xml-parsing - 发现以元素 'country' 开头的无效内容。 '{country}' 之一是预期的.. 行 '10' ,列 '14'

转载 作者:行者123 更新时间:2023-12-03 11:17:17 25 4
gpt4 key购买 nike

我正在尝试解决此问题,但无法理解此错误的根本原因:

Invalid Content Was Found Starting With Element 'country'. One Of '{country}' Is Expected.. Line '10', Column '14'



这是我的 xml:

<?xml version="1.0"?>
<!--DTD file reference-->
<!--<!DOCTYPE countries SYSTEM "http://localhost:8080/ajaxprac/file.dtd">-->

<!--DTD file reference-->
<!---->
<countries xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://localhost:8080/ajaxprac"
xsi:schemaLocation="http://localhost:8080/ajaxprac fileSchema.xsd">
<country>
<name>pakistan</name>
<cities>
<city>Kassowal</city>
<city>Faisalabad</city>
<city>Multan</city>
</cities>
</country>
<country>
<name>india</name>
<cities>
<city>Agra</city>
<city>Amritsar</city>
<city>Ayodhya</city>
</cities>
</country>
</countries>

和 xsd 文件是:

<?xml version="1.0"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->

<xs:schema version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://localhost:8080/ajaxprac"
xmlns="http://localhost:8080/ajaxprac">

<xs:element name="countries" type="countriesType"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="city" type="xs:string"/>

<xs:complexType name="countriesType">
<xs:sequence>
<xs:element name="country" type="countryType"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="countryType">
<xs:sequence>
<xs:element ref="name"/>
<xs:element name="cities" type="citiesType"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="citiesType">
<xs:sequence>
<xs:element ref="city"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

最佳答案

正如所写,您的架构需要“全局”countries , namecity要在 http://localhost:8080/ajaxprac 中的元素命名空间,但“本地”元素(在 complexType 中声明的元素,即 countrycities )不在命名空间中。您可能想添加 elementFormDefault="qualified" , IE。

<xs:schema version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://localhost:8080/ajaxprac"
xmlns="http://localhost:8080/ajaxprac"
elementFormDefault="qualified">

适用于 targetNamespace到本地和全局元素声明。

关于xml-parsing - 发现以元素 'country' 开头的无效内容。 '{country}' 之一是预期的.. 行 '10' ,列 '14',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17173383/

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