2016-09-21 922 views
1

我的XML有点生疏,但我试图在XML中创建一个本地天气基于Web的api,但尚未完成,但我遇到了错误测试它,这是XML错误:AttValue:“or'expected

error on line 3 at column 16: AttValue: " or ' expected.

我的代码:

<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> 
+0

你是如何产生的?如果您使用XML生成库,则可以保证始终生成格式良好的合法内容。尝试推出自己的产品时,会随着内容随着时间的推移而变化,并为新的角落案例设定自己的错误。 –

+0

...如果您让我们知道您正在使用哪种语言,我们可以提供指向支持良好的库的指针,该库可用于此目的。 –

回答

3

有三个必要的修正,使您的XML well-formed

  1. 变化<county id= 1 ><county id="1">
  2. 添加结果标签为county
  3. &替换为&amp;

这里是你的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

你需要用单或双引号来包装你id属性的值

<county id="1"> 
0

我想你想写:(注意引号)

<country id = "1">