I found this code on W3Schools and improve it , in the end it became sth like this :
<pre lang="xml"><script language= "javascript">
function LoadXML(){
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
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 "Cannot load the "file.xml" .
When I search for this error a topic in this [
link] is the reason of error , So It seems that I can'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