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 6547745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:52:06+00:00 2026-05-25T11:52:06+00:00

I have requested the data from our CGI in XML format. I do this

  • 0

I have requested the data from our CGI in XML format. I do this asynchronously and have a callback function like so:

var serverData;
function serverDataCallback(event) {
    if (event.target.readyState === 4) {
        if(event.target.status === 200) {
            var serverData = event.target.responseXML;
    }
}

If I console.log the event, I get an XMLHttpRequestProgressEvent.

The target.responseXML is exactly what I want, it looks like this in the Chrome debugging console of type Document:

<Params>
    <VCA>
        <Ch0>
            <enable>yes</enable>
        </Ch0>
    </VCA>
</Params>

However, I have no idea how to process this information! I have had a look at lots of tutorials and the following does not work:

serverData.getElementByTagName('Ch0')[0].getElementByTagName('enable')[0]

There is just an exception saying that getElementByTagName does not exist.

If I console.log the serverData it is reported as a Document

I’ve never done an XML HTTP Request to return XML before, so don’t really know what I’m doing! Could anyone shed some light?

  • 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-05-25T11:52:07+00:00Added an answer on May 25, 2026 at 11:52 am

    If you want to use the DOM (like you are in your example), you need to walk down the element tree just as elaborately as the XML document is. You also need to spell the functions correctly; it’s called getElementsByTagName and not getElementByTagName since there’s nothing unique about a tag name and thus the method will return an array of matching elements. A DOM solution would be something like this:

    var xhr = new XMLHttpRequest();
    
    xhr.onreadystatechange = function() {
      if ((this.readyState == 4) && (this.status == 200)) {
        var paramsElement = this.responseXML.getElementsByTagName('Params')[0];
        var vcaElement = paramsElement.getElementsByTagName('VCA')[0];
        var chElement = vcaElement.getElementsByTagName('Ch0')[0];
        var enableElement = chElement.getElementsByTagName('enable')[0];
        var enable = enableElement.data;
    
        console.debug(enable);
      }
    };
    
    xhr.open('GET', 'test.xml');
    xhr.send();
    

    There should of course be a lot of error checking here (each call to getElementsByTagName may return null), but it will hopefully get you started. I would, however, encourage you to not use the DOM or XmlHttpRequest directly, but instead an abstraction like jQuery:

    $.get('test.xml', function(data, textStatus, xhr) {
      var $enable = $(data).find('Params VCA Ch0 enable');
      var enable = $enable.text();
      console.debug(enable);
    }, 'xml');
    

    As you can see, it’s much less code and you get nice translation from the XML to a jQuery object that is a lot more powerful than DOM objects.

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

Sidebar

Related Questions

I have to load XML from external domain, so my code looks like this
I have this code: ... request data = new request(); data.username = formNick; xml
We have a gwt-client, which recieves quite a lot of data from our servers.
I have a web-app-database 3 tier server setup. Web requests data from app, and
In my app i have to send a xml data as request, I am
We have been requested to stream a single video (+500MB) from a web site.
Several of our users have asked us to include data relative to their account
In our application we need to import transaction data from paypal through an API
We have an in-house application that pulls some data from some of Amazon's pages
I'm using GAPI to try and create simple reports from our Google Analytics data.

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.