3

I have a XML file saved in my local machine and I want to read it through javascript. The following is my local xml path D:\user\xml\test1.xml.

<script>
  if (window.XMLHttpRequest)
   {
      xmlhttp=new XMLHttpRequest();
   }
  else
  {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 xmlhttp.open("GET","file///D:/user/xml/test1.xml",true);
 xmlhttp.send();
 xmlDoc=xmlhttp.responseXML;
 alert(xmlDoc);
 </script>

I find no response in alert. I am a newbie to XML and learning to code now. Is my system path specification correct? How to check whether my request opens the xml file and reads the input?

Sam
  • 5,040
  • 12
  • 43
  • 95
  • I was wondering if it is a copy/paste error that you forgot the opening brackets on your if and else? – Zack Jun 18 '15 at 16:10
  • 1
    You should check out the [File API](http://www.html5rocks.com/en/tutorials/file/dndfiles/) for reading local files. – ray Jun 18 '15 at 16:11
  • And also, you are missing the colon `:` after "file" – Zack Jun 18 '15 at 16:12
  • I will stop using the internet if this is possible without the user actually selecting the file... – madflow Jun 18 '15 at 16:19
  • Then how http://www.w3schools.com/xml/tryit.asp?filename=tryxml_parsertest is this possible – Sam Jun 18 '15 at 16:34

1 Answers1

-3

Try to get the XML file you want to read into the project folder and access it as ../data.