解析XML 2

解析XML 2

问题描述:

我想用煎茶触摸解析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' 
     } 
    } 

我没有得到所有的数据,你可以尝试把你的浏览器中的网址。

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

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