XML错误:AttValue:“或'预期

时间:2016-09-21 15:29:58

标签: xml

我的XML有点生疏,但我正在尝试用XML创建一个基于Web的本地天气api。但是它没有完成,但我在测试时遇到了错误,这是

  第16行第3行的

错误:AttValue:“或'预期。

我的代码:

<local_weather>
    <local_counties>
        <county id = 1>
            <name> Suffolk </name>
                <location>
                    api.openweathermap.org/data/2.5/weather?q=Ipswich,uk&APPID=6ce0e1da2bbce97fe9e735c3a2009c71  
                </location>
            <name> Norfolk </name>
                <location>
                    api.openweathermap.org/data/2.5/weather?q=Norwich,uk&APPID=da4be448d33cb1b0d8b5bdaa4daca4f7
                </location>
            <name> Essex </name>
                <location>
                    api.openweathermap.org/data/2.5/weather?q=Chelmsford,uk&APPID&APPID=9fa167ffbd810a6cdbf0fe73597d92fe
                </location>
            <name> Cambridgeshire </name>
                <location>
                    api.openweathermap.org/data/2.5/weather?q=Peterborough,uk&APPID&APPID=2dcefd34930d723d95c0c3d910f90c3d
                </location>
  </local_counties>
</local_weather>

3 个答案:

答案 0 :(得分:3)

要使XML well-formed ,需要进行三次更正:

  1. <county id= 1 >更改为<county id="1">
  2. county添加结束标记。
  3. &替换为&amp;
  4. 以下是您的XML已更正为格式良好:

    <local_weather>
        <local_counties>
            <county id ="1">
                <name> Suffolk </name>
                <location>
                    api.openweathermap.org/data/2.5/weather?q=Ipswich,uk&amp;APPID=6ce0e1da2bbce97fe9e735c3a2009c71  
                </location>
                <name> Norfolk </name>
                <location>
                    api.openweathermap.org/data/2.5/weather?q=Norwich,uk&amp;APPID=da4be448d33cb1b0d8b5bdaa4daca4f7
                </location>
                <name> Essex </name>
                <location>
                    api.openweathermap.org/data/2.5/weather?q=Chelmsford,uk&amp;APPID&amp;APPID=9fa167ffbd810a6cdbf0fe73597d92fe
                </location>
                <name> Cambridgeshire </name>
                <location>
                    api.openweathermap.org/data/2.5/weather?q=Peterborough,uk&amp;APPID&amp;APPID=2dcefd34930d723d95c0c3d910f90c3d
                </location>
            </county>
      </local_counties>
    </local_weather>
    

答案 1 :(得分:1)

您需要使用单引号或双引号包装id属性的值。

<county id="1">

答案 2 :(得分:0)

我想你想写:

<country id = "1">

(注意引号。)

相关问题