Saturday, 12 December 2015

XML : GulpJS - how to read value from xml file and add it to a json file?

I'm a bit of a noob to Gulp/Node programming and I'm struggling to do a simple task :)

I have an XML file which contains a node like this: <widget version="1.1"></widget>

I would like to read out the version value and put that value into a json file. How is this achieved?

Here's what I tried:

  var configXml      = 'config.xml';  var enTemplateJson = 'signing/en_template.json';    

CODE:

SCRIPT:

  return gulp.src([configXml])            .pipe(cheerio({              parserOptions: {                xmlMode: true              },              run: function($, file) {                $('widget').each(function() {                  var version = $(this)[0].attribs.version;                    // prints version 1.1                  console.log(version);                })              }            }))            .pipe(gulp.dest('test.xml'));    

No comments:

Post a Comment