2013-05-26 46 views
0

我想用煎茶觸摸解析XML,我已經試過在stckovrflow所有的可能性,但沒有任何的顯示:解析XML 2

XML數據: 來自:http://www.aufaitmaroc.com/feeds/maroc.xml

商店:

Ext.define("MyApp2.store.NewsStore", { 
extend: "Ext.data.Store", 
requires: ["Ext.data.proxy.JsonP", "Ext.dataview.List", "MyApp2.model.News"   ,"Ext.data.reader.Xml"], 
config: { 
model: "MyApp2.model.News", 
autoLoad: true, 
proxy: { 
    type: 'jsonp', 
    url: 'http://www.aufaitmaroc.com/feeds/maroc.xml', 
    reader: { 
     type: 'xml', 
     record: 'item', 
     rootProperty: 'channel' 
     } 
    } 
}  
}); 

我的模型:

Ext.define("MyApp2.model.News", { 
extend: "Ext.data.Model", 
config: { 
type:'tree', 
fields: [ 
{name: 'title', type: 'auto'} 

] 
    } 
    }); 

我的觀點:

{ 
        xtype: "list", 
        store: "NewsStore", 
        itemTpl: '<h1>{title}</h1>' 
} 

我在鍍鉻的控制檯這樣的錯誤:

Picture from my browser

我試圖解決我的問題: 我在httpd.conf中的添加此阿帕奇(IM使用WampServer)

AddType application/x-font-woff .woff 
    AddType application/rss+xml .xml 

和我創建:的httpd-proxy.conf並把它額外的文件夾

我的httpd-proxy.conf

ProxyRequests Off 
ProxyPreserveHost On 

<Proxy *> 
Order deny,allow 
Allow from all 
</Proxy> 

ProxyPass /EMBackend http://localhost:8383/MyApp2/index.html 
ProxyPassReverse /EMBackend http://localhost:8383/MyApp2/index.html 
<Location /EMBackend> 
    Order allow,deny 
    Allow from all 
</Location> 

我有這個到httpd.conf:

Include conf/extra/httpd-proxy.conf 

&還是老樣子無法顯示任何數據。任何幫助將不勝感激:)

PS:我嘗試使用JSONP那樣:

 proxy: { 
    type: 'jsonp', 
    url: 'https://ajax.googleapis.com/ajax/services/feed/load?   v=1.0&q=http://www.aufaitmaroc.com/feeds/maroc.xml', 
    reader: { 
     type: 'json', 
     rootProperty: 'responseData.feed.entries' 
     } 
    } 

我沒有得到所有的數據,你可以嘗試把你的瀏覽器中的網址。

回答

2

AFAIK JSONP不能使用xml。您將需要使用像yql這樣的服務將xml轉換爲json。 This fiddle is demo of doing that

Ext.define('MyApp.model.Station', { 
    extend: 'Ext.data.Model', 
    config: { 
     fields: [ 
      'title' 
     ] 
    } 
}); 

Ext.define('MyApp.store.Stations', { 
    extend: 'Ext.data.Store', 
    requires: 'MyApp.model.Station', 
    config: { 
     autoLoad: true, 
     model: 'MyApp.model.Station', 
     proxy: { 
      type: 'jsonp', 
      //url : 'http://www.aufaitmaroc.com/feeds/maroc.xml', 
      url: 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20rss%20where%20url%20%3D%20%22http%3A%2F%2Fnews.google.co.in%2Fnews%3Fpz%3D1%26cf%3Dall%26ned%3Din%26hl%3Den%26output%3Drss%22&format=json&diagnostics=true', 
      reader: { 
       type: 'json', 
       rootProperty: 'query.results.item' 
      } 
     } 
    } 
}); 

Ext.define('MyApp.list.List', { 
    extend: 'Ext.List', 
    config: { 
     fullscreen: true, 
     itemTpl: '{title}', 
     store: Ext.create('MyApp.store.Stations') 
    } 
}); 

Ext.create('MyApp.list.List'); 

使用YQL, 轉到YQL控制檯頁面 - http://developer.yahoo.com/yql/console/

類型在YQL語句框中鍵入以下行。 「SELECT * FROM RSS其中URL =‘http://www.aufaitmaroc.com/feeds/maroc.xml’」

上的單選按鈕的側選擇下面

清除在單選按鈕JSON選項輸入框中。它應該是空的。

取消勾選「診斷」和「調試」複選框。

然後按'測試'按鈕。這應該給你下面的輸出。

現在,所有這一切,轉到頁面的底部。應該有'THE REST QUERY'部分。 有一個網址。請注意,在該網址中,網址末尾會顯示'& callback ='之類的內容。刪除它,並使用剩餘的作爲商店的網址。 url的回調部分由sencha自動處理。

+0

謝謝你回答,但我是新的js,我沒有得到如何以及我在哪裏必須把我的網址(http://www.aufaitmaroc.com/feeds/maroc.xml)爲了轉換爲json? –

+0

我已經更新了關於YQL的答案。 – blessenm

+0

謝謝你,它工作正常!我的救星! –