Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read XML File using Javascript from a Local Folder

Tags:

javascript

xml

I am trying to learn how to read into a web page data in an XML file. This is a static HTML page. I do not want a web server and I cannot use Ajax. The XML file is local (in the same directory as the HTML file). I want this to work in a Chrome browser.

What I need to do is:

  1. Read the XML file on the page onLoad event.
  2. Use innerHTML to insert the XML data into a div.

My problem is in reading the XML file. All of the examples I have found I think will only work if there is a web server running, which I have to avoid.

like image 610
MES5464 Avatar asked Dec 31 '12 22:12

MES5464


1 Answers

If you're reading another file the only way to do that with front end JS is another request (ajax). If this were node.js it would be different because node can access the filesystem. Alternatively if you get the xml into a javascript string on the same page, you can manipulate it. There are a number of good libraries (jquery's parseXML).

like image 113
Zeke Nierenberg Avatar answered Sep 23 '22 17:09

Zeke Nierenberg