Skip to content Skip to sidebar Skip to footer

How To Get Xml Data By Using Ajax

I am trying to get my xml data by using ajax call. But I am getting only ROOT Node value data in my result.responseXML. Not able to access ITEM tag data. My XML.

Solution 1:

In Ext js, the best way to read xml data is to use a store.

  1. Create a store and define the fields (the mapping property (@Val) is used to indicate this is an attribute instead of a child element);
  2. Use an ajax proxy to load the data;
  3. Use an xml reader to read the data. In Ext js 6, you define the name of the root element and name of the elements you want to obtain;
  4. Load the store and show the value of the first element in the console.

var itemStore = Ext.create('Ext.data.Store', {
    fields: [{name: 'val', mapping: '@Val'}, 
        {name: 'data', mapping: '@data'}],
    proxy: {
        type: 'ajax',
        url: 'data1.xml',
        method: 'GET',
        reader: {
            type: 'xml',
            record: 'ITEM',
            rootProperty: 'ROOT'
        }
    }
});

itemStore.load(function(records, operation, success) {
    var item1 = itemStore.first();
    console.log("First item " + item1.get('val'));
});

Check the fiddle here: https://fiddle.sencha.com/#view/editor&fiddle/1vd6

Post a Comment for "How To Get Xml Data By Using Ajax"