2016-09-21 113 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">