Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I found this code on W3Schools and improve it , in the end it became sth like this :

JavaScript
<pre lang="xml"><script language= "javascript">
    function LoadXML(){
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      try{
    xmlhttp.open("GET","file.xml",false);
        alert("first place");

    xmlhttp.send();
        alert("2nd place");
    }
    catch(err){
    alert(err.message);
    }
    xmlDoc=xmlhttp.responseXML;

    document.write("<table><tr><th>Artist</th><th>Title</th></tr>");
    var x=xmlDoc.getElementsByTagName("CD");
    for (i=0;i<x.length;i++)
      {
      document.write("<tr><td>");
     alert( document.write(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue));
      document.write("</td><td>");
     alert( document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue));
      document.write("</td></tr>");
      }
    document.write("</table>");
    }
    </script>



This code is available in :[W3School Code]

But when I want to run this code in my own PC , an error occur in try and catch block !
It shows that &quot;Cannot load the &quot;file.xml&quot; .
When I search for this error a topic in this [link] is the reason of error , So It seems that I can&#39;t do something like that in my Own PC cuz it uses http and need a server or a local host .

But This code is for a project in my class and one of the scenarios is (Retrieve Element of An XML File and show its content on my HTML page) !

I am sure that they will test this program on their own PCs .

So can anyone explain me a way to accomplish this scenario in A PC ?!

Note : The target browser is IE 8.0

Thanks in advance
Posted
Comments
Zoltán Zörgő 29-Jan-15 16:42pm    
Why not jquery?

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900