发现以元素“国家"开头的无效内容.应为“{country}"之一.“10"行,“14"列 [英] Invalid Content Was Found Starting With Element 'country'. One Of '{country}' Is Expected.. Line '10', Column '14'

查看:23
本文介绍了发现以元素“国家"开头的无效内容.应为“{country}"之一.“10"行,“14"列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to resolve this issue but could not understand the root cause of this error:

发现以元素country"开头的无效内容.应为{country}"之一.10"行,14"列

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>

推荐答案

正如所写,您的架构需要全局"countriesnamecity 元素位于 http://localhost:8080/ajaxprac 命名空间中,但本地"元素(在 complexType 中声明的元素,即 countrycities) 位于 no 命名空间中.您可能想要添加 elementFormDefault="qualified",即

As written, your schema expects the "global" countries, name and city elements to be in the http://localhost:8080/ajaxprac namespace, but the "local" elements (those declared inside a complexType, i.e. country and cities) to be in no namespace. You probably want to add elementFormDefault="qualified", i.e.

<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 应用于本地和全局元素声明.

which applies the targetNamespace to local, as well as global, element declarations.

这篇关于发现以元素“国家"开头的无效内容.应为“{country}"之一.“10"行,“14"列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆