加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml-parsing – 从元素’country’开始发现无效的内容 一个'

发布时间:2020-12-16 08:03:39 所属栏目:百科 来源:网络整理
导读:我正在尝试解决这个问题,但不能理解这个错误的根本原因: 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--!--!DO
我正在尝试解决这个问题,但不能理解这个错误的根本原因:

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应用于本地以及全局元素声明。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读