Created
September 27, 2014 11:44
-
-
Save syui/3dbce2177fe17e8df9b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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