View Full Version : Cannot retrieve XML attribute with Ext.DomQuery

16 Feb 2011, 12:27 PM
Hi, guys!
I have following problem: cannot retrieve attribute from XML node with Ext.DomQuery!

I receive following XML from server:

<response status="ok" message="">
<user id="54">
<email>[email protected]</email>

and then I want to retrive next info: first name, email. userId.

I do it with following code (this is success handler in Ext.Ajax.request):

success: function(response, options) {
var xml = response.responseXML;
if (Ext.DomQuery.selectNode('error', xml)) {
// report error here ....
} else if (Ext.DomQuery.selectNode('response[status=ok]', xml)) {
// response is OK, retrieve data
var firstName = Ext.DomQuery.selectValue('first_name', xml);
var email = Ext.DomQuery.selectValue('email', xml);
var userId = Ext.DomQuery.selectValue('user/@id', xml);
// do other stuff

So, this line of code:

var userId = Ext.DomQuery.selectValue('user/@id', xml);

set userId=undefined.

How can I retrieve 'id' attribute from <user> node?


thank you in advance for your help!


17 Feb 2011, 2:01 AM
I just tried a simplified version of that and it works fine for me.


Response.ContentType = "text/xml"
Response.Write("<response status='ok' message=''><users><user id='54'><first_name>test</first_name></user></users></response>")


Ext.onReady(function() {
url: './scripts/test.aspx',
success: function(response)
var xml = response.responseXML;
console.log(Ext.DomQuery.selectValue('user/@id', xml)); // displays 54!

You can also try:

var userNode = Ext.DomQuery.selectNode('user', xml);

(Note, I only checked this in Firefox.)

2 Apr 2012, 1:48 AM
Trying to use the syntax E[foo] has an attribute "foo"

this was not working so had to get the attribute as in the previous post. Thanks for sharing your findings guys and Sencha please take a look !>:)