1

I have my JavaScript and XML files in the same folder. I'd like to be able to parse through the XML using the JavaScript, but I don't know how to get the JavaScript file to "talk" to the XML file. I've looked up ways, but they all involved server requests, which I don't need. How do I get the JavaScript to read-in the local XML file to make use of it?

I'd eventually want to be able to convert the XML to JSON and then have my JavaScript parse through that, which I think I know how to do. I just don't know how to get the JavaScript to take data from the XML. I'm a beginner so any help is appreciated.

Thanks!

Thomas G
  • 21
  • 1
  • 2

1 Answers1

0

Are your planning to use NodeJS for it? If so, see The best node module for XML parsing . I've used xml-stream and it works pretty well. For a cross-browser solution: Cross-Browser Javascript XML Parsing .

Regarding the 'talking to the browser', if in NodeJS, use fs module. Otherwise (browser), use the FileAPI (see https://scotch.io/tutorials/use-the-html5-file-api-to-work-with-files-locally-in-the-browser) and then the crossbrowser solution above.

See the compatibility table for the FileAPI: http://caniuse.com/#feat=fileapi (all modern browsers)

Community
  • 1
  • 1
Ciro Costa
  • 2,455
  • 22
  • 25
  • Thanks for the response. I haven't considered using NodeJS. What would the benefit of doing so be? – Thomas G Jan 21 '15 at 20:12
  • That depends on your goal. NodeJS provides a runtime for javascript decoupled from the browser, letting you access local content with ease. If you're only doing some scripting, then nodejs would fit well. If you're willing to provide a great UI and something that you expect zero-config, then browser & web technologies are the best fit. There's actually a lot of benefits from both sides, just thought rapidly of two. Go check it out, you'll definetly enjoy! – Ciro Costa Jan 21 '15 at 20:27