PDA

View Full Version : Example to read nested XML file received from REST type of webservice.



sagar.uplenchwar
30 Jun 2011, 10:49 AM
Hi,
I am new to sencha touch. I am trying to read nested XML file from REST type of webservice.
The XML file looks like.

<LicenseKey licensedTo="sagar">
<DefaultQuoteTypes>
<QuoteType name="one" code="INV"/>
<QuoteType name="two" code="INV"/>
<QuoteType name="Group" code="GRP"/>
<QuoteType name="Volunt" code="VOL"/>
</DefaultQuoteTypes>
<Products>
<Product name="product1" code="u1">
<States>
<State name="Arizona" code="AZ"/>
<State name="California" code="CA"/>
<State name="Connecticut" code="CT"/>
<State name="Florida" code="FL"/>
<State name="Hawaii" code="HI"/>
<State name="Illinois" code="IL"/>
<State name="Indiana" code="IN"/>
<State name="Maryland" code="MD"/>
<State name="Massachusetts" code="MA"/>
<State name="Michigan" code="MI"/>
<State name="Nevada" code="NV"/>
<State name="New Hampshire" code="NH"/>
<State name="New Jersey" code="NJ"/>
<State name="New York" code="NY">
<excludedQuoteTypes>
<excludedQuoteType name="Group" code="GRP"/>
<excludedQuoteType name="Volunt" code="VOL"/>
</excludedQuoteTypes>
</State>
<State name="Ohio" code="OH"/>
<State name="Virginia" code="VA"/>
</States>
</Product>
<Product name="product2" code="u2">
<States>
<State name="Arizona" code="AZ"/>
<State name="California" code="CA"/>
<State name="Connecticut" code="CT"/>
<State name="Florida" code="FL"/>
<State name="Hawaii" code="HI"/>
<State name="Illinois" code="IL"/>
<State name="Indiana" code="IN"/>
<State name="Maryland" code="MD"/>
<State name="Massachusetts" code="MA"/>
<State name="Michigan" code="MI"/>
<State name="Nevada" code="NV"/>
<State name="New Hampshire" code="NH"/>
<State name="New Jersey" code="NJ"/>
<State name="Ohio" code="OH"/>
<State name="Virginia" code="VA"/>
</States>
</Product>
</Products>
</LicenseKey>


I have written nested Model and store with associations like this.

Model


Ext.regModel('LicenseKey', {
fields: [ 'licensedTo'],

associations:[
{type:'hasMany',model:'DefaultQuoteTypes',name:'DefaultQuoteType'},
{type:'hasMany',model:'Products',name:'Product'}
],
validations:[
{type: 'presence', field: 'licensedTo'},
]
});


Ext.regModel('DefaultQuoteTypes', {
fields: [],
hasMany:{model:'QuoteType',name:'QuoteType'},
belongTo:{model:'LicenseKey',name:'LicenseKey'}
});

Ext.regModel('QuoteType', {
fields: ['name','code'],
belongTo:{model:'DefaultQuoteTypes',name:'DefaultQuoteTypes'}
});

Ext.regModel('Products', {
fields: [],
hasMany:{model:'Product1',name:'Product'},
belongTo:{model:'LicenseKey',name:'LicenseKey'}
});
Ext.regModel('Product1', {
fields: ['name','code'],
//hasMany:{model:'States',name:'States'},
belongTo:{model:'Products',name:'Products'}
});
Ext.regModel('States', {
fields: [],
hasMany:{model:'State',name:'State'},
belongTo:{model:'Product1',name:'Product'}
});
Ext.regModel('State', {
fields: ['name','code'],
hasMany:{model:'excludedQuoteType',name:'excludedQuoteTypes'},
belongTo:{model:'States',name:'States'}
});
Ext.regModel('excludedQuoteType', {
fields: ['name','code'],
belongTo:{model:'State',name:'State'}
});


Data store.

var login1=Ext.data.Store({
model:'LicenseKey',
autoLoad:true,
method:GET,
proxy:{
type: 'rest',
//url:'',
reader:{
type:'xml',
record:'LicenseKey'


}
}

});

Can anyone suggest me how to verify and display correct data using template?