Page 1 of 3 123 LastLast
Results 1 to 10 of 29

Thread: [OPEN-724] Problem with attribute mapping in XMLReader

    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1

    Default [OPEN-724] Problem with attribute mapping in XMLReader

    I'm seeing "SYNTAX_ERR: DOM Exception 12", when using the '@' prefix on record field mapping.

    This is the same bug as reported here: http://www.sencha.com/forum/showthre...=xml+attribute under "Help & Discussion". I'm bumping this up as a bug.

    The patch that is given at the end of that article thread is a workaround. This patch should be applied officially to the XMLReader.

  2. #2
    Sencha User edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939

    Default

    Oddly I can't reproduce this in my unit tests. I've pasted the full test below - all of this passes whereas it sounds like you're expecting the 'email' test to fail. What do I need to change to reproduce your environment?

    Code:
    describe("reading data", function() {
        var readData, user;
    
        beforeEach(function() {
            Ext.regModel('spec.XmlReader', {
                fields: [
                    {name: 'id',    mapping: 'idProp', type: 'int'},
                    {name: 'name',  mapping: 'FullName', type: 'string'},
                    {name: 'email', mapping: '@email', type: 'string'}
                ]
            });
    
            reader = new Ext.data.XmlReader({
                root: 'data',
                idProperty: 'idProp',
                totalProperty: 'totalProp',
                messageProperty: 'messageProp',
                successProperty: 'successProp',
                model: 'spec.XmlReader',
                record: 'user'
            });
            
            ajaxResponse = new MockAjax();
    
            //FIXME: Has to be a better way?
            responseText = "<results> \
                <totalProp>2300</totalProp> \
                <successProp>true</successProp> \
                <messageProp>It worked</messageProp> \
                <data> \
                    <user email=\"[email protected]\"> \
                        <idProp>123</idProp> \
                        <FullName>Ed Spencer</FullName> \
                    </user> \
                </data> \
            </results>";
            
            ajaxResponse.complete({
                status: 200,
                statusText: 'OK',
                responseText: responseText,
                responseHeaders: {
                    "Content-type": "application/xml"
                }
            });
            
            readData = reader.read(ajaxResponse);
            user = readData.records[0];
        });
        
        it("should extract the correct total", function() {
            expect(readData.total).toEqual(2300);
        });
    
        it("should extract success", function() {
            expect(readData.success).toEqual(true);
        });
        
        it("should extract count", function() {
            expect(readData.count).toEqual(1);
        });
    
        it("should extract the message", function() {
            expect(readData.message).toEqual("It worked");
        });
    
        it("should extract the id", function() {
            expect(user.getId()).toEqual(123);
        });
    
        it("should respect field mappings", function() {
            expect(user.get('name')).toEqual("Ed Spencer");
        });
        
        it("should respect field mappings containing @", function() {
            expect(user.get('email')).toEqual("[email protected]");
        });
    });
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  3. #3
    Sencha Premium Member
    Join Date
    Mar 2011
    Posts
    15

    Default

    I also have the same problem

    Place of Exception in sencha-touch.js

    Ext.DomQuery = {
    /**
    * Selects a group of elements.
    * @param {String} selector The selector/xpath query (can be a comma separated list of selectors)
    * @param {Node/String} root (optional) The start of the query (defaults to document).
    * @return {Array} An Array of DOM elements which match the selector. If there are
    * no matches, and empty Array is returned.
    */
    select : function(q, root) {
    ...
    q = q.split(",");
    for (i = 0, qlen = q.length; i < qlen; i++) {
    if (typeof q[i] == 'string') {
    -------> nodes = root.querySelectorAll(q[i]);

  4. #4
    Sencha Premium Member
    Join Date
    Mar 2011
    Posts
    15

    Default

    some kind of fix for example

    for (i = 0, qlen = q.length; i < qlen; i++) {
    if (typeof q[i] == 'string') {
    if (q[i][0]!='@') {
    nodes = root.querySelectorAll(q[i]);
    } else {
    nodes = root.getAttribute(iq[i].substring(1));
    }

  5. #5

    Default Same issue

    I'm having the same problem:

    This is my xml struture:

    <?xml version='1.0' encoding='UTF-8'?>
    <response status= '200'>
    <message><![CDATA[main regions found]]></message>
    <regions>
    <region id='82'>
    <name><![CDATA[Argentina]]></name>
    <description><![CDATA[The Argentine industry behind Chile.]]></description>
    <parent id=''></parent>
    <image id='364'><![CDATA[files/364.gif]]></image>
    </region>
    <wine_region id='119'>
    <name><![CDATA[Australia]]></name>
    <description><![CDATA[The description]]></description>
    <parent id=''></parent>
    <image id='181'><![CDATA[files/181.jpg]]></image>
    </region>
    </regions>
    </response>



    This is my code:

    function modelsInit(){
    Ext.regModel('Region', {
    fields: [{name: 'name', type: 'string'},
    {name:'id' , mapping:'@id'},
    {name: 'description', type: 'string'}]
    });
    }

    I Get the Name and the desription... but each time I try to map to an attribute with @, it throws :
    SYNTAX_ERR: DOM Exception 12: An invalid or illegal string was specified.
    sencha-touch-debug-w-comments.js on line 21719.


    Thanks for your help!

  6. #6
    Sencha User
    Join Date
    Jun 2011
    Posts
    2

    Question

    Is there any news on this?

    I just had the very same issue. Got it working with the XMLReader.createAccessor patch:

    http://www.sencha.com/forum/showthre...l=1#post517459

    But shouldn't this work as advertised?

    (Edit: i'm using Sencha Touch 1.1.0)

  7. #7
    Sencha User
    Join Date
    Jul 2011
    Location
    Melbourne Australia
    Posts
    8

    Default Broken for me too ...

    I get the DOM Exception error at about line 21758 in sencha-touch-debug-w-comments.js

    Senca-touch V1.1.0 GPL version.
    OS X 10.7 Safari Version 5.1 (7534.48.3)

    Here's the relevant variables just before the exception, and then some tests in the console:
    PHP Code:
    root
    <program title=?"Masterchef Australia" subTitle=?"Monday - Week 12" programFlags=?"0" category=?"reality/?real-life" fileSize=?"0" seriesId=?"212535185" hostname=?"ebony" catType programId repeat=?"0" stars=?"0" endTime=?"2011-07-18T20:?30:?00" startTime=?"2011-07-18T19:?30:?00" lastModified=?"2011-07-18T12:?55:?04">??</program>?

    q
      
    "@title"

    root.querySelectorAll("@title")
      
    DOMException
      code
    12
      constructor
    DOMExceptionConstructor
      line
    2
      message
    "SYNTAX_ERR: DOM Exception 12"
      
    name"SYNTAX_ERR"
      
    sourceId4773632976
      __proto__
    DOMExceptionPrototype

    root.querySelectorAll("program[title]")
      []

    root.querySelectorAll("Program[title]")
      []

    root.querySelectorAll("Program[@title]")
      
    DOMException

    root.getAttribute("@title")
      
    null

    root.getAttribute("title")
      
    "Masterchef Australia" 
    > represents commands typed on the console.

    My xml file is served with Content -Type of application/xml but it doesn't have the <?xml .... ?> header, it simply starts with <!DOCTYPE Status>.

    I'm not sure if not having the <?xml .... ?> header makes any difference to how the DOM is interpreted for the xml document.

    The patch/work around/override at http://www.sencha.com/forum/showthre...l=1#post517459 seems to do the job.

    Glad I found this bug, I was going nuts trying to figure out why this wasn't working!

    Cheers,
    Troy.

  8. #8

    Default Unfortunatelly same problem

    Sad to say i'm fighting entire day with my very first app done in Sencha.
    You can imagine my frustration trying for 3 hours figure out what is wrong, because I got DOM Exception 12 when using @attr.

    My code is less than simple:
    Code:
    new Ext.Application({
        onReady: function() {
        
            Ext.regModel('TreeItem', {
                fields: [{name: 'Label', mapping: '@Label'}]
            });
    
        var    store = new Ext.data.Store({
                model: 'TreeItem',
                autoLoad: 'true',
                proxy: {
                    type: 'ajax',
                    url: 'tree.xml',
                    reader: {
                        type: 'xml',
                        root: 'TSLTree',
                        record: 'HObject'                    
                    }
                }
            });
            
            
        var list = new Ext.List({
            title: 'HD Objects',
            indexBar: true,
            fullscreen: true,                
            itemTpl: '{Label}',
            store: store
        });
        
        list.show();
        }
    });
    When I replace attribute (@Label) with label element, all works fine....

  9. #9
    Sencha User edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939

    Default

    What browser are you using and what does your XML look like?
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  10. #10
    Touch Premium Member
    Join Date
    Mar 2011
    Location
    New Jersey, USA
    Posts
    130

    Default

    I've experienced these dom exceptions when reading my xml data and ive worked around it by stripping out the escape characters (which caused the parser/reader to blow up) and replacing them with escaped escape characters. It was pretty complicated at first, but this is an example of what I did inside one of my functions:

    PHP Code:
    createDropdownOptions: function(store){
                var 
    = new Array(), = new Array();
                
    a.push({text' 'value''});  //in case user wants to clear their previous selection
                
    var model store.model.modelName;
                for(var 
    0store.data.items.lengthi++){               
                    
    text  store.data.items[i].data.LDS
                    
    value store.data.items[i].data.ECD
               
                    if(
    text != '' && value != ''){
                        var 
    text;
                        if(
    text.indexOf("'") != -1){ //finds an apostrophe in the xml and replaces it with
                                                     //something that doesn't cause the exception
                            
    text.replace("'""~");
                        }
                        
    Ext.util.Format.format('{text: \'{0}\', value: \'{1}\'}'tvalue);
                        if(
    s.indexOf("~") == -1){
                            
                            
    myObject = eval('(' ')');
                        }
                        else{
                            
    s1 s.substring(0s.indexOf("~"));
                            
    s2 s.substring(s.indexOf("~") + 1);
                            
    myObject = eval('(' s1 "\\'" s2 ')');
                        }
                        
                        if(
    c.indexOf(s) == -1){  //only add's unique objects to a
                            
    c.push(s);
                            
    a.push(myObject);
                        }
                    }
                }
                return 
    a;
            } 
    I'd also like to know more about this, though.

Page 1 of 3 123 LastLast

Similar Threads

  1. XmlReader mapping to XML attribute
    By Davi Baldin in forum Ext 1.x: Help & Discussion
    Replies: 7
    Last Post: 16 Jan 2012, 4:34 PM
  2. problem with attribute mapping in xml reader?
    By djkraz in forum Sencha Touch 1.x: Discussion
    Replies: 7
    Last Post: 21 Nov 2011, 7:33 AM
  3. XMLReader -> Attribute Mapping -> Ext.DomQuery?
    By Aigu in forum Sencha Touch 1.x: Discussion
    Replies: 2
    Last Post: 23 Aug 2011, 1:24 PM
  4. [OPEN] [OPEN-724] Problem with disabled property
    By ricoux63 in forum Ext 3.x: Bugs
    Replies: 1
    Last Post: 17 Jun 2010, 4:12 PM
  5. Problem with XmlReader and mapping
    By de in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 30 Apr 2008, 12:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •