2011-09-21 54 views
0
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> 

回答

0

讓模型具有xml屬性和使用xml代理的商店。

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

然後,您將在商店中解析xml的內容。全部閱讀全文http://dev.sencha.com/deploy/touch/docs/?class=Ext.data.Store