PDA

View Full Version : XMLStore



gameboy87
31 Jul 2012, 1:05 AM
I have the XML of this format


<?xml version="1.0" encoding="UTF-8"?>
<users>
<meta>
<name>Spencer</name>
</meta>
<user>
<id>1</id>
<name>Ed Spencer</name>
<email>ed@sencha.com</email>
</user>
<user>
<id>2</id>
<name>Abe Elias</name>
<email>abe@sencha.com</email>
</user>
</users>




How to define the store/model to access <name> tag's value inside the <meta> tag ?

My store is,


Ext.define('User', {
extend: 'Ext.data.Model',
fields: [{name:'id', mapping: 'user > id',type: 'string'},
{name:'name',mapping: '@name'}
]
});


var store = Ext.create('Ext.data.Store', {
autoLoad:true,
model: 'User',
proxy: {
type: 'ajax',
url : 'users.xml',
reader: {
type: 'xml',
record: 'users',
root: 'users'
}
}
});



Am I correct in this way ?.

sword-it
31 Jul 2012, 5:35 AM
Hi

Try this model For nested xml -


Ext.define('app.model.Name', {
extend: 'Ext.data.Model',
fields: [{
name: 'name',
mapping: 'name',
type: 'string'}]
});

Ext.define('app.model.User', {
extend: 'Ext.data.Model',
fields: [{
name: 'id',
mapping: 'id',
type: 'int'},
{
name: 'name',
mapping: 'name',
type: 'string'},
{
name: 'email',
mapping: 'email',
type: 'string'}],

associations: [{
type: 'hasMany',
model: 'app.model.Name',
name: 'name',
associationKey: 'User',
reader: {
type: 'xml',
record: 'meta',
root: 'meta'
}}
],
proxy: {
type: 'ajax',
url: 'data/example.xml',
reader: {
type: 'xml',
record: 'User',
root: 'Users'
}
}
});


Read API docs http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Model-cfg-associations

gameboy87
5 Aug 2012, 10:26 PM
Will try it out this way and reply soon.