Skip to content

Instantly share code, notes, and snippets.

@syui
Created September 27, 2014 11:44
Show Gist options
  • Save syui/3dbce2177fe17e8df9b2 to your computer and use it in GitHub Desktop.
Save syui/3dbce2177fe17e8df9b2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
var parser = require('xml2json');
//var argv = require('node-argv')
var re = /(?:\.([^.]+))?$/;
var typ = process.argv[2]
var ext = re.exec(typ)[1];
if (ext === "xml") {
var fs = require('fs')
, filename = process.argv[2];
fs.readFile(filename, 'utf8', function(err, xml) {
if (err) throw err;
//console.log(xml)
var json = parser.toJson(xml); //returns a string containing the JSON structure by default
console.log(json);
});
} else {
var xml = process.argv[2];
var json = parser.toJson(xml); //returns a string containing the JSON structure by default
console.log(json);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment