1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    9
    Vote Rating
    0
    moneta will become famous soon enough

      0  

    Default Unanswered: Ext Js4 - Directly load xml data to the xml store works improperly?

    Unanswered: Ext Js4 - Directly load xml data to the xml store works improperly?


    Hi all,
    I got problem while directly loading the xml data into xml store. Maybe I am missing something.

    Here goes my code:

    1. Define model:
    Code:
    Ext.define('MoneFox.model.SchemaRelation', {
        extend: 'Ext.data.Model',
    
        fields: [
            {
                name: 'fromcode',
                type: 'string'
            },
            {
                name: 'lookup',
                type: 'string'
            }
        ]
    });
    2. Define store:
    Code:
    Ext.define('MoneFox.store.SchemaRelations', {
        extend: 'Ext.data.Store',
        requires: [
            'MoneFox.model.SchemaRelation'
        ],
    
        constructor: function(cfg) {
            var me = this;
            cfg = cfg || {};
            me.callParent([Ext.apply({
                storeId: 'SchemaRelations',
                model: 'MoneFox.model.SchemaRelation',
                proxy: {
                    type: 'memory',
                    reader: {
                        type: 'xml',
                        record: 'link'
                    },
                    writer: {
                        type: 'xml',
                        record: 'link'
                    }
                }
            }, cfg)]);
        }
    });
    3. XML Data:
    HTML Code:
    <Schema>
      <link>
        <fromcode>ACTIVI</fromcode>
        <lookup>(Select * from Activity where Type='A')</lookup>
      </link>
      <link>
        <fromcode>ACTIVI\MARCAP</fromcode>
        <lookup>ACTIVI.MarCode = MARCAP.Code</lookup>
      </link>
      <link>
        <fromcode>ACTIVI\EMPL</fromcode>
        <lookup>ACTIVI.EmpCode = EMPL.Code</lookup>
      </link>
      <field>
        <node>MarCode</node>
        <table>ACTIVI</table>
        <name>MarCode</name>
      </field>
    </Schema>
    4. Directly load xml store with xml data using loadRawData:
    Code:
    var store = Ext.data.StoreManager.lookup('SchemaRelations');
    
    store.on('load', function(){
        alert(store.getTotalCount());
    });
    
    store.loadRawData("<Schema> <link> <fromcode>ACTIVI</fromcode> <lookup>(Select * from Activity where Type='A')</lookup> </link> <link> <fromcode>ACTIVI\MARCAP</fromcode> <lookup>ACTIVI.MarCode = MARCAP.Code</lookup> </link> <link> <fromcode>ACTIVI\EMPL</fromcode> <lookup>ACTIVI.EmpCode = EMPL.Code</lookup> </link> <field> <node>MarCode</node> <table>ACTIVI</table> <name>MarCode</name> </field></Schema>");
    
    console.log(store.data);
    5. And here are weird results:
    - The alert on the event store on load display getTotalCount of 384 ?!?
    - The console.log shows object having 02 items, but all items have empty value: fromcode = "" and lookup = "" ?!?

    Pls. anyone could kindly help. Thanks.

  2. #2
    Sencha - Community Support Team sword-it's Avatar
    Join Date
    May 2012
    Location
    Istanbul
    Posts
    1,333
    Answers
    124
    Vote Rating
    85
    sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough

      0  

    Default


    Hi moneta,

    problem in your reader config -
    Code:
     proxy: {
                    type: 'memory', 
                   reader: {
                        type: 'xml',
                        record: 'link'   // It's root: 'link'
                    },
                    writer: {
                        type: 'xml',  
                      record: 'link'    // It's root: 'link'
                    }            }
    record is not valid config it's "root" .
    sword-it.com, Sencha Developer House in Turkey - Istanbul University Technopark Suite 204.

  3. #3
    Sencha User
    Join Date
    Feb 2012
    Posts
    9
    Vote Rating
    0
    moneta will become famous soon enough

      0  

    Default


    Hi Sword,
    Thanks a lot for your reply. I have just tried to reconfigured it to root: 'link but it doesn't work.

    I think the root should be 'Schema' and the record is still 'link'. Because I did try to create another store folowing instruction in http://docs.sencha.com/ext-js/4-1/#!.../xml-grid.html , type ajax with url point to the the file containing this xml, then it worked perfectly.

    It looks like that the reader have somehow reads the xml but fail to map it to memory store data ? The getTotalCount = 384 is actually the strlen of the xml data string.

    Best,
    Moneta

  4. #4
    Sencha User
    Join Date
    Feb 2012
    Posts
    9
    Vote Rating
    0
    moneta will become famous soon enough

      0  

    Default Is this a bug of loadRawData function?

    Is this a bug of loadRawData function?


    Anyone could help on this, please ?

  5. #5
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,949
    Answers
    461
    Vote Rating
    636
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    You're passing it a string, it's expecting an XML document.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  6. #6
    Sencha User
    Join Date
    Feb 2012
    Posts
    9
    Vote Rating
    0
    moneta will become famous soon enough

      0  

    Default


    How can I do that? I tried this but it doesn't work.
    Code:
    store.loadRawData("
    <?xml version="1.0" encoding="UTF-8"?>
    <Schema> <link> <fromcode>ACTIVI</fromcode> <lookup>(Select * from Activity where Type='A')</lookup> </link> <link> <fromcode>ACTIVI\MARCAP</fromcode> <lookup>ACTIVI.MarCode = MARCAP.Code</lookup> </link> <link> <fromcode>ACTIVI\EMPL</fromcode> <lookup>ACTIVI.EmpCode = EMPL.Code</lookup> </link> <field> <node>MarCode</node> <table>ACTIVI</table> <name>MarCode</name> </field></Schema>");

  7. #7
    Sencha User
    Join Date
    Feb 2012
    Posts
    9
    Vote Rating
    0
    moneta will become famous soon enough

      0  

    Default How to send xml doc to loadRawData ?

    How to send xml doc to loadRawData ?


    I stuck with this one for serveral days. Anyone could help, please?

  8. #8
    Sencha User
    Join Date
    Feb 2012
    Posts
    9
    Vote Rating
    0
    moneta will become famous soon enough

      0  

    Default Solved/

    Solved/


    I got it worked. Just like to share with you if you might get the same issues. The code is just sample like this:

    Code:
    data = '<?xml version="1.0" encoding="UTF-8"?>
    <Schema> <link> <fromcode>ACTIVI</fromcode> <lookup>(Select * from Activity where Type='A')</lookup> </link> <link> <fromcode>ACTIVI\MARCAP</fromcode> <lookup>ACTIVI.MarCode = MARCAP.Code</lookup> </link> <link> <fromcode>ACTIVI\EMPL</fromcode> <lookup>ACTIVI.EmpCode = EMPL.Code</lookup> </link> <field> <node>MarCode</node> <table>ACTIVI</table> <name>MarCode</name> </field></Schema>';
    if ( window.DOMParser ) { // Standard tmp = new DOMParser(); xml = tmp.parseFromString( data , "text/xml" ); } else { // IE xml = new ActiveXObject( "Microsoft.XMLDOM" ); xml.async = "false"; xml.loadXML( data ); } console.log(xml); // --> It shows "document" ;-) store.loadRawData(xml);
    Thanks to the post in http://stackoverflow.com/questions/4...ng-jquery-json

    Best,
    Moneta