-
18 Mar 2013 11:07 PM #1
Answered: Read Xml data and bind into the list in sencha touch 2
Answered: Read Xml data and bind into the list in sencha touch 2
Hi guys,
This is my first sencha project mobile apps.
I want read the xml from url and show it on list view in sencha touch2.
very urgent friends....
is it possible?
Xml format will be like this,
<stations>
<station id="48">
<name>xxx96</name>
<city>mmmm</city>
<state>ffff</state>
<latitude>25.94589</latitude>
<longitude>-80.203683</longitude>
</station>
<station id="50">
<name>abc</name>
<city>yyy</city>
<state>xxx</state>
<latitude>25.94589</latitude>
<longitude>-80.203683</longitude>
</stations>
-
Best Answer Posted by mitchellsimoens
With this XML (based on yours but with a closing </station>):
You can use a store and model like:Code:<?xml version="1.0" encoding="UTF-8"?> <stations> <station id="48"> <name>xxx96</name> <city>mmmm</city> <state>ffff</state> <latitude>25.94589</latitude> <longitude>-80.203683</longitude> </station> <station id="50"> <name>abc</name> <city>yyy</city> <state>xxx</state> <latitude>25.94589</latitude> <longitude>-80.203683</longitude> </station> </stations>
Code:Ext.define('MyApp.model.Station', { extend : 'Ext.data.Model', config : { fields : [ { name : 'id', mapping : '@id' }, 'name', 'city', 'state', 'latitude', 'longitude' ] } }); Ext.define('MyApp.store.Stations', { extend : 'Ext.data.Store', requires : 'MyApp.model.Station', config : { model : 'MyApp.model.Station', proxy : { type : 'ajax', url : 'data/xml.xml', reader : { type : 'xml', rootProperty : 'stations', record : 'station' } } } });
-
20 Mar 2013 11:15 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3108
With this XML (based on yours but with a closing </station>):
You can use a store and model like:Code:<?xml version="1.0" encoding="UTF-8"?> <stations> <station id="48"> <name>xxx96</name> <city>mmmm</city> <state>ffff</state> <latitude>25.94589</latitude> <longitude>-80.203683</longitude> </station> <station id="50"> <name>abc</name> <city>yyy</city> <state>xxx</state> <latitude>25.94589</latitude> <longitude>-80.203683</longitude> </station> </stations>
Code:Ext.define('MyApp.model.Station', { extend : 'Ext.data.Model', config : { fields : [ { name : 'id', mapping : '@id' }, 'name', 'city', 'state', 'latitude', 'longitude' ] } }); Ext.define('MyApp.store.Stations', { extend : 'Ext.data.Store', requires : 'MyApp.model.Station', config : { model : 'MyApp.model.Station', proxy : { type : 'ajax', url : 'data/xml.xml', reader : { type : 'xml', rootProperty : 'stations', record : 'station' } } } });Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
24 Apr 2013 12:52 AM #3
Thanks mitchell
Thanks mitchell
works fine.. Thanks Lot


Reply With Quote