-
23 Feb 2012 2:49 PM #1
Nested XML duplicate field issue
Nested XML duplicate field issue
Hey all,
I seem to have run across a potential bug when reading nested XML.
Here is a sample xml structure:
Notice how we have title tags nested within subitem and one under each item. However, the title tag that is a direct child of item is listed below the nested sub items.Code:<?xml version="1.0" encoding="utf-8"?> <data> <items> <item> <subitems> <subitem> <title>A Subtitle</title> </subitem> <subitem> <title>Another Subtitle</title> </subitem> </subitems> <title>Some Title</title> </item> <item> <subitems> <subitem> <title>A Subtitle</title> </subitem> <subitem> <title>Another Subtitle</title> </subitem> </subitems> <title>Some Title</title> </item> </items> </data>
When I read this structure with associations and want to get the <title> of <item> the data being returned to the field in the model is the first title in the list of subitems rather than the title tag in item.
Here is a sample store:
And here is the models with associations:PHP Code:app.stores.testStore = Ext.regStore('testStore', {
model: app.models.test,
proxy: {
type: 'ajax',
url: 'path/to/test.xml',
reader: {
type: 'xml',
root: 'items',
record: 'item'
},
},
});
When I use the code below to read the data for the first <item> and subseuqently its <title> I am getting a value of "A Subtitle" which is the title of the first subitem rather then the expected "A Title" which is the title of the first item.PHP Code:app.models.subitem = Ext.regModel('subitem', {
fields: [
{name: 'title', type: 'string'},
],
belongsTo: 'test',
proxy: {
type: 'memory',
reader: {
type: 'xml',
root: 'subitems',
record: 'subitem'
},
},
});
app.models.test = Ext.regModel('test', {
fields: [
{name: 'title', type: 'string'}
],
hasMany: ['SubItems', {model: 'subitem', name: 'subitems'}],
});
Am I doing something wrong or is this a bug?PHP Code:var test = app.stores.test;
test.load();
test.on('load', function(){
console.log(test.getAt(0).data.title);
}
-
23 Feb 2012 4:02 PM #2
I wanted to mention that I could solve this by placing the <title> tag for item above the <subitems> tag, however, this XML structure in my case is predefined and not something I can edit prior to loading.
Thanks!
-
24 Feb 2012 9:53 AM #3Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
Looks like first one first served no matter the level.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
24 Feb 2012 10:44 AM #4
Yup,
The only workaround I can think of at the moment is to create a proxy to read all of the <title> elements and then test if the parent_id is the correct one before using it. For deeply nested xml this adds quite a bit of unneeded parsing and I haven't implemented it yet, but it's an idea.
Any idea if this has been (or will be) fixed in Sencha v2.0?
Thanks!
Success! Looks like we've fixed this one. According to our records the fix was applied for
TOUCH-2245
in
2.1.


Reply With Quote