Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grunt - Read XML File

Tags:

gruntjs

I am new to grunt. I'm trying to figure out how to read an .xml file from a grunt task. Ideally, I'd like to load the xml into JSON. However, I can't figure out how to even read an .xml file from a grunt task. Does anyone have an example of how to do this?

Thank you!

like image 730
SL Dev Avatar asked Dec 02 '13 19:12

SL Dev


2 Answers

If you want something that doesn't require python or a c compiler, and is synchronous, try node-xml-lite:

var parseXML = require('node-xml-lite').parseString;
var webConfigDoc = parseXML(grunt.file.read('../web.config'));

The parsed document object can be a little tricky to work with, but underscore find* methods can help.

like image 190
webXL Avatar answered Oct 02 '22 13:10

webXL


  1. Try grunt-convert - XML to JSON config example is near the end of the README
  2. Write a plugin based upon node-xml2json?
like image 29
Matthew Bakaitis Avatar answered Oct 02 '22 12:10

Matthew Bakaitis