Results 1 to 3 of 3

Thread: Cannot retrieve XML attribute with Ext.DomQuery

  1. #1
    Sencha User
    Join Date
    Sep 2009
    Location
    Russia, Saint-Petersburg
    Posts
    13

    Default Cannot retrieve XML attribute with Ext.DomQuery

    Hi, guys!
    I have following problem: cannot retrieve attribute from XML node with Ext.DomQuery!

    I receive following XML from server:

    HTML Code:
    <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):


    Code:
    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:

    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.

  2. #2
    Sencha User fay's Avatar
    Join Date
    Apr 2007
    Location
    Ireland
    Posts
    1,750

    Default

    I just tried a simplified version of that and it works fine for me.

    test.aspx

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

    Code:
     
    Ext.onReady(function() {
      Ext.Ajax.request({
        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:

    Code:
     
    var userNode = Ext.DomQuery.selectNode('user', xml);
    console.log(userNode.attributes.getNamedItem('id').value);
    (Note, I only checked this in Firefox.)

  3. #3
    Sencha User
    Join Date
    Feb 2012
    Posts
    255

    Default I had problems too

    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 !

Similar Threads

  1. XMLReader -> Attribute Mapping -> Ext.DomQuery?
    By Aigu in forum Sencha Touch 1.x: Discussion
    Replies: 2
    Last Post: 23 Aug 2011, 1:24 PM
  2. DomQuery xpath attribute check
    By alupuli in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 15 Oct 2009, 2:21 AM
  3. Replies: 0
    Last Post: 13 Sep 2007, 1:41 AM
  4. DomQuery _nodup attribute
    By INeedADip in forum Ext 1.x: Bugs
    Replies: 1
    Last Post: 22 Jun 2007, 10:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •