PDA

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



iryndin
16 Feb 2011, 12:26 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="">
<users>
<user id="54">
<sys_role_id>1</sys_role_id>
<title>null</title>
<first_name>Suman</first_name>
<middle_name>null</middle_name>
<last_name>K</last_name>
<email>[email protected]</email>
<phone>1231231234</phone>
<phone_ext>123</phone_ext>
<cell>1231231234</cell>
<comments>test</comments>
<password_retries>0</password_retries>
<is_update_password>false</is_update_password>
<is_locked>false</is_locked>
<date_last_login>null</date_last_login>
<alerts>147</alerts>
</user>
</users>
</response>

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);
//console.log(userId);
// 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?

Guys,

thank you in advance for your help!

Regards,
Ivan.