View Full Version : Searching through raw for nested data

15 Oct 2010, 6:19 AM
I am trying to find a way to read nested xml-data, with variable number of certain nested data. In the example below are 2 contacts , but there could also be 5 contacts. I was thinking about using the convert function in a model to construct an array with all contacts. But I cannot get access to the raw data, though it is present in the record of the convertfunction. Anybody got any idea how to acces the raw data? Or have a better way of reading variable number of nested xml-data?

<other attributes>...</other attributes>
Ext.regModel('Order', {
fields : [
name: 'id',
type: 'integer',
defaultValue: 666
mapping: 'contacts',
convert: function(v, rec){
.... (searching raw data for contacts)

18 Oct 2010, 11:44 PM
I have made absolutely no headway in my search to be able to read nested xml data.

This example doesn't work. It doesn't contain any of the contacts after 'order' has been read.

,hasMany:[{model: 'contact', mapping:'contacts', name:'contacts',foreignKey:'order_id', ownerModel:'order', primaryKey:'id',
model: 'contact',
proxy: {
id: 'id'
},reader: {
type: 'xml',
root: 'contact'

And when I try something like this I get:
Uncaught TypeError: Object [object Object] has no method 'querySelectorAll'

,{name: 'contact',mapping:'contacts > contact', convert: (function(){
var reader2 = new Ext.data.XmlReader({
record: 'contacts',
model : 'contact',
type: 'xml',
return function(v, n) {
return reader2.readRecords(n).records;

19 Nov 2010, 10:19 AM
I got the same issue...

Have you solved it or someone have founded any solution?

21 Nov 2010, 11:31 PM
I have found a way, though it is far from ideal. After the initial reading you take '((store.getProxy()).getReader()).xmlData' (with a read listener). This contains the raw xml data. After that you can put an xml reader on the raw data.

var reader = new Ext.data.XmlReader( {
model : 'Option',
type : 'xml',
root : 'd > order > car > options > option'

var result = reader.readRecords(rawData);

After that you connect the two entities with a foreign key, which references to the other entity. This works for me, but I still hope that they make a working and clear xml mapping example.

22 Nov 2010, 5:41 PM
1.0 and before had some fairly limited XML reading support - especially when it came to loading associations. I've just committed a patch to finally allow nested XML data to be parsed natively based on your configured associations - this will be present in the next patch release (which is imminent).

See http://www.sencha.com/forum/showthread.php?115033-FIXED-583-nested-xml-complex-xml-cant-get-associations-to-work for more background. Sorry for the delay in implementing this.

29 Nov 2010, 6:32 PM
@Ed, glad you have a solution worked out. I gotta say, Sencha Touch is really awesome. However... for those of us who have been banging our heads against the same brick wall for days (i.e. me), can you give us an ETA for the next release, or maybe share your fix in the form of an override?

18 Sep 2011, 1:38 PM

Thanks to bobbaluba (http://www.sencha.com/forum/member.php?284497-bobbaluba)!