我正在尝试解决这个问题,但不能理解这个错误的根本原因:
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>
如你所愿,您的架构期望“全球”国家,名称和城市元素位于http:// localhost:8080 / ajaxprac命名空间中,而“local”元素(在complexType(即国家和城市)内)没有命名空间。你可能想添加
elementFormDefault="qualified"
,即
<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应用于本地以及全局元素声明。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。