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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:01:33+00:00 2026-06-13T23:01:33+00:00

I am new to Stack OverFlow and coding in general. I am trying to

  • 0

I am new to Stack OverFlow and coding in general. I am trying to take an XML file and render it in the browser using JavaScript. I have looked around at some sample code of how to do this and came up with the following code:

<!DOCTYPE html>
<html>
<body>

<script>
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.open("GET","social.xml",false);
  xmlhttp.send();
  xmlDoc=xmlhttp.responseXML; 

document.write("<table border='1'>");
var x=xmlDoc.getElementsByTagName("CD");
for (i=0;i<x.length;i++)
  { 
  document.write("<tr><td>");
  document.write(x[i].getElementsByTagName("c_id")[0].childNodes[0].nodeValue);
  document.write("</td><td>");
  document.write(x[i].getElementsByTagName("facebook_id")[0].childNodes[0].nodeValue);
  document.write("</td></tr>");
  }
  document.write("</table>");
</script>

</body>
</html>

Anyway, when I run this on my local server none of the data that I am trying to display in the table appears. My .html file and .xml file are in the same folder, so I believe I have the correct file pathway. I could just be making a rookie mistake here, but I can’t for the life of me figure out why a table listing the c_id and facebook_id values is not being created. I looked around for answers and haven’t been able to find any. Any help would be greatly appreciated. Thanks!

  • 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-13T23:01:34+00:00Added an answer on June 13, 2026 at 11:01 pm

    You need to add an onload event listener to the xmlhttprequest before sending the request. Also, you might need to parse the XML with a DOMParser. Anyway, this should work on modern browsers:

    <!DOCTYPE html>
    <html>
        <body>
    
            <script>
                if (window.XMLHttpRequest)
                {// code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp=new XMLHttpRequest();
                }
                else
                {// code for IE6, IE5
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
    
    
    
                xmlhttp.onload = function() {
                    var xmlDoc = new DOMParser().parseFromString(xmlhttp.responseText,'text/xml');
    
                    console.log(xmlDoc);
    
                    document.write("<table border='1'>");
                    var x=xmlDoc.getElementsByTagName("CD");
                    for (i=0;i<x.length;i++)
                    { 
                        document.write("<tr><td>");
                        document.write(x[i].getElementsByTagName("c_id")[0].childNodes[0].nodeValue);
                        document.write("</td><td>");
                        document.write(x[i].getElementsByTagName("facebook_id")[0].childNodes[0].nodeValue);
                        document.write("</td></tr>");
                    }
                    document.write("</table>");
    
                }
    
    
                xmlhttp.open("GET","social.xml",false);
                xmlhttp.send();
                </script>
    
        </body>
    </html>
    

    Now, just a couple of things worth mentioning about what you’re doing:

    • xmlhttprequest objects have many different parameters that mean a variety of things: readystate, status code, the works. You might benefit looking a bit more into those.

    • document.write should really never be used, ever. In fact, any means of HTML injection should be handled very carefully. You could use a template-based solution common in many MVC-esque frameworks, or mine if you want 🙂

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

Sidebar

Related Questions

I'm new to both stack overflow and using jQuery from scratch, so forgive me
I am new to Stack Overflow and Ruby on Rails. My problem is, when
I am very much new to stack overflow so I do apologize if I
I'm new to SOA (and to Stack Overflow too...) Some services and web applications
I am new here and hope my first question meets stack overflow's requirements. I
This is my first time using Stack Overflow, so if I've done something wrong
I have just started coding with rails. I am using: Rails 3.2.8 ruby 1.9.3p194
I have been using the new Windows Azure Websites preview to build a site
I've started using Project Euler to improve my objective-c coding and have worked through
I am trying to find the source of an intermittent Stack Overflow exception on

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.