Success! Looks like we've fixed this one. According to our records the fix was applied for TOUCH-2245 in a recent build.
  1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    21
    Vote Rating
    1
    swardson is on a distinguished road

      0  

    Default 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:

    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>
    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.

    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:

    PHP Code:
    app.stores.testStore Ext.regStore('testStore', {
        
    modelapp.models.test,
        
        
    proxy: {
            
    type'ajax',
            
    url'path/to/test.xml',
            
            
    reader: {
                
    type'xml',
                
    root'items',
                
    record'item'
            
    },
        },    
    }); 
    And here is the models with associations:

    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'}],
    }); 
    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:
    var test app.stores.test;
    test.load();

    test.on('load', function(){
        
    console.log(test.getAt(0).data.title);

    Am I doing something wrong or is this a bug?

  2. #2
    Sencha User
    Join Date
    Feb 2012
    Posts
    21
    Vote Rating
    1
    swardson is on a distinguished road

      0  

    Default


    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!

  3. #3
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,541
    Vote Rating
    872
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Looks like first one first served no matter the level.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  4. #4
    Sencha User
    Join Date
    Feb 2012
    Posts
    21
    Vote Rating
    1
    swardson is on a distinguished road

      0  

    Default


    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!

Thread Participants: 1

Tags for this Thread