Grunt - Reading an XML File

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

Thanks!

+6
source share
3 answers

If you want something that does not require python or the 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 may be a little complicated to work with, but the find * underline methods may help.

+4
source
+2
source

Reading xml is pretty simple: use libxmljs .

 var libxmljs = require("libxmljs"); var xml = grunt.file.read(f); var xmlDoc = libxmljs.parseXml(xml); 
+1
source

Source: https://habr.com/ru/post/959194/


All Articles