Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7975671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:42:26+00:00 2026-06-04T08:42:26+00:00

Well, this issue is making me mad. I think that I have a lack

  • 0

Well, this issue is making me mad. I think that I have a lack of knowledge in this aspect.

I am trying to parse a XML response, everything is ok but the problem is when I try to access to objects. I treat them like arrays and I always receive “undefined”:

<?xml version="1.0" encoding="UTF-8" ?>
  <ajax-response>
   <response>
    <item>
      <name><![CDATA[ok]]></name>
      <value><![CDATA[true]]></value>
    </item>
    <item>
      <name><![CDATA[menuDiv]]></name>
      <value><![CDATA[Some HTML value]]></value>
    </item>
   </response>
  </ajax-response>

And here is the Jquery code:

xmlDoc = $.parseXML( xml ),
        $xml = $( xmlDoc ),
        $item = $xml.find( "item" );
        alert($item.length);
        $item.each(function(key, value){ 
            alert(typeof value);     
        });

This line alert(typeof value); returns “object”. However, if I do value[0] or $value[0] it returns “undefined”.

I would like to get “Some HTML value” from the object.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:42:27+00:00Added an answer on June 4, 2026 at 8:42 am

    The value object passed into your iteration function will be an XML DOM node, in your case an Element with the tag name item. So you’d retrieve information from it by getting attributes from it, or looking at the text in any child TextNodes that it has.

    You can wrap the element in a jQuery instance and use jQuery’s attr to get attributes, and text to get text.

    I would like to get “Some HTML value” from the object.

    That would be text — here’s an example:

    $item.each(function(key, value){ 
        var $value = $(value);
        alert(typeof $value.text());
    });
    

    Here’s a full example that loops through the children of each item: Live copy | source

    jQuery(function($) {
    
      var xml =
          '<?xml version="1.0" encoding="UTF-8" ?>' +
          '<ajax-response>' +
              '<response>' +
                  '<item>' +
                      '<name><![CDATA[ok]]></name>' +
                      '<value><![CDATA[true]]></value>' +
                  '</item>' +
                  '<item>' +
                      '<name><![CDATA[menuDiv]]></name>' +
                      '<value><![CDATA[Some HTML value]]></value>' +
                  '</item>' +
              '</response>' +
          '</ajax-response>';
    
      var xmlDoc = $.parseXML( xml ),
          $xml = $( xmlDoc ),
          $item = $xml.find( "item" );
      display($item.length);
      $item.each(function(key, value){ 
        $(value).children().each(function(clave, valor) {
          display("$(valor).text() = " + $(valor).text());
        });
      });
    
      function display(msg) {
        $("<p>").html(msg).appendTo(document.body);
      }
    });
    

    Or if you just want to grab the value that’s the sibling of the name containing the text "menuDiv", the relevant bit is:

    var menuDivText = $xml.find("item name:contains(menuDiv)").next().text();
    

    Live example | source

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well hi, guess what, I have an IE positioning issue! This is in 8,
I'm currently making a note web app that going pretty well. I have the
I have been trying to wrap my head around this issue but I am
Well this is a really weird issue, I really didn't find anything on this
Well this is weird let me describe the scenario I have this mailer define
I have a class extends NamedParameterJdbcDaoSupport. well this superclass has a final setDataSource method
I hope I can explain this well enough so that you can understand the
I have this account creation email that is sent out to anyone who is
I have an annoying display issue in IE (7/8). I have some tabs that
we are running into an odd issue when trying to parse an input file.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.