1. #1
    Sencha User
    Join Date
    Feb 2013
    Posts
    3
    Vote Rating
    0
    udhayakumark is on a distinguished road

      0  

    Default 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>




  2. With this XML (based on yours but with a closing </station>):

    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>
    You can use a store and model like:

    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'
                }
            }
        }
    });

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,656
    Vote Rating
    435
    Answers
    3108
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    With this XML (based on yours but with a closing </station>):

    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>
    You can use a store and model like:

    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.

  4. #3
    Sencha User
    Join Date
    Feb 2013
    Posts
    3
    Vote Rating
    0
    udhayakumark is on a distinguished road

      0  

    Default Thanks mitchell

    Thanks mitchell


    works fine.. Thanks Lot