开发者

How to parse a local xml file mentioned below in sencha touch mobile

开发者 https://www.devze.com 2023-04-06 23:33 出处:网络
As i am new to Sencha touch mobile stuck in parsing a normal xml file and pass it to a store object and populate in a panel view. Can any one help me out how to parse a XML file kept locally in the pr
As i am new to Sencha touch mobile stuck in parsing a normal xml file and pass it to a store object and populate in a panel view. Can any one help me out how to parse a XML file kept locally in the project(as mentioned below data.xml) or as a string. Below is the XML and thanks in advance.


data.XML:-

<dataSrc>
    <section>
        <elem>
                 <id>1677</id>
                 <name>
                 <![CDATA[  United Kingdom]]>
                </name>  
         </elem>

    </section>
     <section>
        <elem>
                 开发者_如何转开发<id>1678</id>
                 <name>
                 <![CDATA[  United Arab Emirates]]>
                </name>  
         </elem>

    </section>
        .......
</dataSrc>


Have a model with the xml properties and a store with a xml proxy.

Ext.regModel('elem', {
    fields: [
        {name: 'id', type: 'string'},
        {name: 'name',  type: 'string'}
    ]
});

var myStore = new Ext.data.Store({
    model: 'elem',
    proxy: {
        type: 'xml',
        url : '/data.xml',
        reader: {
            type: 'xml',
            root: 'dataSrc',
            record: 'elem'
        }
    },
    autoLoad: true
});

Then you have the contents of the xml parsed in the store. Read all about this at http://dev.sencha.com/deploy/touch/docs/?class=Ext.data.Store

0

精彩评论

暂无评论...
验证码 换一张
取 消