Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 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. #11

    Default

    I have tried IE9 on Win7 and Safari on iPad.
    XML used would be something like that:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <TSLTree>
     <HObject Label="Demo" ObjID="abc" ObjType="ROOT" KeyValue="1" Class="ROOT" ConnectedObjSetID="" ChildrenValid="1">
      <HObject Label="Botan" ObjID="123" ObjType="COUNTRY" KeyValue="113" Class="COUNTRY" ConnectedObjSetID=""></HObject>
      <HObject Label="Dickson 12" ObjID="345" ObjType="COUNTRY" KeyValue="41" Class="COUNTRY" ConnectedObjSetID=""></HObject>
      <HObject Label="Klippan 19" ObjID="147" ObjType="COUNTRY" KeyValue="147" Class="COUNTRY" ConnectedObjSetID=""></HObject>
      <HObject Label="Kv Kronoparken 1:1" ObjID="654" ObjType="COUNTRY" KeyValue="145" Class="COUNTRY" ConnectedObjSetID=""></HObject>
      <HObject Label="NK" ObjID="149" ObjType="COUNTRY" KeyValue="149" Class="COUNTRY" ConnectedObjSetID=""></HObject>
      <HObject Label="Norska Kyrkan" ObjID="71" ObjType="COUNTRY" KeyValue="71" Class="COUNTRY" ConnectedObjSetID=""></HObject>
      <HObject Label="Universitetsbiblioteket" ObjID="1|112" ObjType="COUNTRY" KeyValue="112" Class="COUNTRY" ConnectedObjSetID=""></HObject>
      <HObject Label="Vasaparken" ObjID="5453" ObjType="COUNTRY" KeyValue="3" Class="COUNTRY" ConnectedObjSetID=""></HObject>
     </HObject>
    </TSLTree>
    If changed to sample like that, then it works:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <TSLTree>
      <HObject>
       <Label>test</Label>
      </HObject>
      <HObject>
       <Label>test2</Label>
      </HObject> 
    </TSLTree>
    and model to:
    Code:
    new Ext.Application({
        onReady: function() {
        
            Ext.regModel('TreeItem', {
                fields: [{name: 'Label', mapping: 'Label'}]
            });
    As I have said, that was my first 2-3 hours with Sencha Touch and maybe I have messed something up... The only thing I need is working example of Model/Store/Reader that is using XML where elements have attributes. Preferably with hierarchical data in XML and NestedList as view.

    Thank you very much for your interest and support!

  2. #12

    Default

    ok, I gave up the XML for now and switched to JSON. It works.

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

    Default

    Quote Originally Posted by MaciejZabielski View Post

    If changed to sample like that, then it works:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <TSLTree>
      <HObject>
       <Label>test</Label>
      </HObject>
      <HObject>
       <Label>test2</Label>
      </HObject> 
    </TSLTree>
    My xml is always set up like that. That is how it should be set up. It's the best way for Stores/readers to go through xml in that format.

  4. #14

    Default

    And how do you store hierarchical data in XML without attributes?
    This does not look to good for me.... and NestedList is all about hierarchical data.
    Code:
    <Root>
      <Object>
         <Object></Object>
         <Attr></Attr>
      </Object>
    </Root>

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

    Default

    Unfortunately, this is the way to do it:

    Code:
    <state>
         <name>California</name>
         <population>33871648</population>
         <capital>Sacramento</capital>
         <bird>Quail</bird>
         <flower>Golden Poppy</flower>
         <area units="square miles">155959</area>
              <friends>
                    <friend>
                            <firstName>Tom</firstName>
                            <lastName>Marshall</lastName>
                    </friend>             
                    <friend>                 
                           <firstName>Ed</firstName>
                            <lastName>Norton</lastName>
                    </friend>
              </friends> 
    </state>
    But, if you want to use nested lists, just stick with JSON.
    I've never gotten XML to work with nested lists.

  6. #16
    Sencha Premium Member
    Join Date
    Mar 2011
    Posts
    15

    Default

    Is this fix in sencha-touch-debug-w-comments.js
    I sent in "18 Mar 2011 8:27 AM" not helpful ?

    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));
    }

  7. #17
    Sencha Premium Member
    Join Date
    Mar 2011
    Posts
    15

    Default

    Here is this fix as a full piece of code to drop in source and not to change sencha....js
    Code:
    <script type="text/javascript">
    //workaround for xml attributes reading - Uncaught Error: SYNTAX_ERR: DOM Exception 12
    Ext.DomQuery.select = function(q, root) {
                var results = [],
                    nodes,
                    i,
                    j,
                    qlen,
                    nlen;
    
                root = root || document;
                if (typeof root == 'string') {
                    root = document.getElementById(root);
                }
    
                q = q.split(",");
                for (i = 0, qlen = q.length; i < qlen; i++) {
                    if (typeof q[i] == 'string') {
                    if (q[i][0]!='@') {
                        nodes = root.querySelectorAll(q[i]);
                        for (j = 0, nlen = nodes.length; j < nlen; j++) {
                            results.push(nodes[j]);
                           }
                    } else {
                        nodes = root.getAttributeNode(q[i].substring(1));
                        results.push(nodes);
                    }
                }
    
               }
            return results;
            };
    </script>

  8. #18

    Default

    Yes, your fix does help a lot! Anyway it is fairly difficult to handle XML input. I have to stick with that as my server will return only XML. I will have to load one level at a time (that is not a big problem as I will have fairly large data chunks anyway). Is there any way to pre-process XML data received by proxy before it is rendered? (In jQuery ajax I would use "on success" and than return modified data)

  9. #19
    Sencha Premium Member
    Join Date
    Mar 2011
    Posts
    15

    Default

    I don't know if it is optimal code, but works -
    OnSuccess you can change store, for example

    Code:
    store1.load({
    callback: function(records, operation, success) {
    			    	var list =[];
    			    	list.push(records[0].data);
    store1.loadData(list,false);
     		        }
     		})

  10. #20

    Default

    Any idea how to make this mapping work:
    {name: 'leaf', type: 'boolean', mapping: '@leaf'}

    It worked with JSON data, but not with XML attribute: leaf="true"

    Thanks.

Page 2 of 3 FirstFirst 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
  •