PDA

View Full Version : problem in accessing store data using XmlReader



nthamizhan
24 Apr 2008, 3:37 AM
Hi All,

I am getting the XML data from server using store and XmlReader. But after loaded the data, if i try to get the data from store, i couldn't able to get the records. In callback, it returns always blank record array. Also my content type is application/xml. Please find my below code snippet.

var loadedDevs = Ext.data.Record.create([
{name: 'deviceaddress', type: 'string'}
]);


var devsStore = new Ext.data.Store({
url: 'devices.xml',
scope:this,
reader: new Ext.data.XmlReader({
record: 'loadedDevs',
totalRecords: 'totalDevices'
}, [
{name: 'deviceaddress', mapping: 'deviceaddress'}
]),
sortInfo:{field:'deviceaddress', direction:'ASC'}
});

devsStore.load({callback:function(r, options, success){console.log('callback::' + r);}, scope:this});


<?xml version="1.0" encoding="ISO-8859-1"?>
<deviceaddressList>
<totalDevices>2</totalDevices>
<dev>
<deviceaddress id="1001">10.10.10.10</deviceaddress>
<deviceaddress id="1002">10.10.10.11</deviceaddress>
</dev>
</deviceaddressList>


Thanks in advance.

Regards,
Sudhakar

Animal
24 Apr 2008, 4:00 AM
http://dev.extjs.com/deploy/dev/docs/?class=Ext.data.XmlReader&member=record



record: 'loadedDevs',


means that you have



<?xml version="1.0" encoding="ISO-8859-1"?>
<deviceaddressList>
<totalDevices>2</totalDevices>
<loadedDevs>
<deviceaddress id="1">1.1.1.1</deviceaddress>
</loadedDevs>
<loadedDevs>
<deviceaddress id="2">2.2.2.2</deviceaddress>
</deviceaddressList>
</loadedDevs>


Obviously, you can't have all your fields at the same level in your XML document. Each one is a field of a different record

Tony Mariella
24 Apr 2008, 4:01 AM
Either your
record: 'loadedDevs' need to change to
record: 'dev'
or your xml need to change from dev to loadedDevs

Animal
24 Apr 2008, 4:03 AM
That's not it. <dev> is not a repeating element representing each individual record. He needs to separate his records out.