get the record value from XML Store in EXT js

2.1k Views Asked by At

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

There are 1 best solutions below

2
On BEST ANSWER

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 ...