tags:

views:

52

answers:

1

Hi,

I am ExtJS for GUI development. I am using XML Store for retrieving the data from server.

My XML looks like this.

<meta>
 <entry>x</entry>
 <entry>Y</entry>
</meta>
<data>
  <value>100</value>
  <value>500</value>
 </data>

Where X=100 and Y=500

How do i retrieve the data and value from this using XMLStore?

+1  A: 

Since the XML structure is not really suitable for what the XML Store/Reader expect, I suggest you parse the XML yourself into a more standard format and then load the data to a JsonStore for example.

Parsing code: (wrote it off the top of my head, so might need some adjustments ...)

var data = [];
var q = Ext.DomQuery;
var entries = q.select('meta > entry', theXML);
var values = q.select('data > value', theXML);
for (var i = 0; i < entries.length; ++i) {
    var recordData = {
        entry: entries[i].firstChild.nodeValue,
        value: values[i].firstChild.nodeValue
    }
    data.push(recordData);
}

Hope it will be useful to you ...

ob1
Thanks for your reply. Is the "theXML" refers to the location of the XML file? In my case, it is exported through a REST API. Is it possible to use the URI in this code instead of the XML file path?
Anandan
The "theXML" is the XML DOM document (or the document root node object). You can get one by doing an AJAX call to your REST API URL and accessing *response.responseXML* on the success callback
ob1
That works for me. Thanks :)
Anandan