PDA

View Full Version : One XML multiple Model



JFFortierQc
4 Nov 2011, 7:25 PM
Hi
I understand the example on the http://docs.sencha.com/touch/1-1/#!/api/Ext.data.XmlReader, well I think, but what if I need to load one XML that contains a lot of data and a list of elements like that for example :

<?xml version="1.0" encoding="UTF-8"?>
<myXML>
<params>
<param1>abc</param1>
<somethingElse>def</somethingElse>
<manyOtherParams>ghi</manyOtherParams>
</params>
<users>
<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>
<user>
<id>3</id>
<name>Dude</name>
<email>dude@sencha.com</email>
</user>
</users>
</myXML>

In this example, I would need an Model containing all the parameters, and another with all the users, just like the example does.

I don't want to load the XML once per model, but once for all.
Any idea?

mitchellsimoens
5 Nov 2011, 6:02 AM
Two ways I see to do this...

Do an Ext.Ajax.request and then create the two Stores by passing in the XML.

Have one Store load and when it loads, load that raw data from the Reader and pass it into the other Store.

JFFortierQc
5 Nov 2011, 8:04 PM
I can't figure out hout this works. Sorry, but I'm a beginner. Here is my code, close to the example, except, that my XML file is in a folder app and named myxml.xml. Also, I add a root params which represent the parent node of my user list.

I tried to display something, but may be I don't understand listeners enought. Here is my code


Ext.regModel('User', {
fields: ['id', 'name', 'email']
});


var store = new Ext.data.Store({
model: 'User',
listeners: {
'load' : function(store,records,options) {
alert(true);
}
},
proxy: {
type: 'ajax',
url : 'app/myxml.xml',
root : 'users',
reader: {
type: 'xml',
record: 'user'
}
}
});

Can you help me on that. I just want to start by loading an XML file. Note, that I on my local folder, not on a server. At the end, it will be an Mobile App that will load that XML.

JFFortierQc
8 Nov 2011, 1:04 PM
I did the load with Ajax, thanks that works.
Actually I donc pass the XML element to the Store, but I create the Model by setting parameter from their own XML node value.

But for problem with Chrome, loading a XML from a server when this is in an APP, I need to change to JSONP.

Thanks