View Full Version : how to select this xpath/xml record?

4 Jun 2008, 2:58 PM

How can I grab the repeating XML state node's inner text with XML reader? What combination of the 'record' and 'mapping' attributes would get the text value?

The following does not work:

var reader = new Ext.data.XmlReader(
{ record: 'address/state' },
[{name: 'foo', mapping: '.'}]

4 Jun 2008, 3:20 PM
This does not work either, though it selects the rows it does not map the inner text.

var reader = new Ext.data.XmlReader(
{ record: 'address/state' },
[{name: 'state', mapping: ''}]

This also does not work, it does find the inner text but it selects only a single row

var reader = new Ext.data.XmlReader(
{ record: 'address' },
[{name: 'state', mapping: 'state'}]

Finally, this doesn't work either, even though it is apparently valid xpath as my first example (using '.') was also.

var reader = new Ext.data.XmlReader(
{ record: 'address/state' },
[{name: 'state', mapping: 'text()'}]

So, is this an ExtJS deficiency? Should I quit trying to do with with Ext and hack my solution or find a different/complementary lib? Or am I simply doing this wrong?

4 Jun 2008, 3:27 PM
in selecting extjs. i should have picked something that doesn't try to mooch money for support, and doesn't have a deceptive license that camouflages itself under gnu but in reality attempts to usurp its derivates as its own.

5 Jun 2008, 12:46 AM
Oh, I was just about to dive in and help you with your seemingly random code. Oh well.

8 Jun 2008, 8:47 AM
Here is the solution:

var reader = new Ext.data.XmlReader(
{ record: 'address/state' },
[{name: 'state', mapping: '/'}]

11 Oct 2009, 1:45 AM
I am not sure if there is something in ExtJS 3 that provides xpath functionality on documents that are not in the DOM but I am using the following function which seems to work on IE 8 and FF.

xPathSelect: function(elem,xpath) {
if(IE) {
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc = elem;
var nodes=xmlDoc.selectNodes(xpath)
var xmlText = serializeXML(nodes[0]);

else {

var xmlDoc = elem;
var nsResolver = xmlDoc.createNSResolver( xmlDoc.ownerDocument == null ? xmlDoc.documentElement : xmlDoc.ownerDocument.documentElement);
//nsResolver = document.createNSResolver(node);
debug("nsResolver: " +nsResolver.lookupNamespaceURI("p"));
var headings = xmlDoc.evaluate(xpath, xmlDoc, nsResolver, XPathResult.UNORDERED_NODE_ITERATOR_TYPE , null);
debug("headings.resultType: " +headings.resultType);
var thisHeading = headings.iterateNext();
var xmlText = serializeXML(thisHeading);
return xmlText;

I call this as follows which seems to work:

method: 'GET',
url: "xml/xprocdefs.xml",
success: function(xhr, options) {
var result = workflow.draw.xPathSelect(xhr.responseXML,xpath);

3 Jan 2011, 3:26 PM
I realize I'm late to the party, but if anybody still needs full XPath capabilities for their XmlReader, I wrote one. Details and source are here on the Sencha User and Plugins forum:


I hope it helps.