Created
February 14, 2013 03:20
-
-
Save timvw/4950357 to your computer and use it in GitHub Desktop.
This file contains 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
var parser = require('xml2json'); | |
var fs = require('fs'); | |
var cwd = process.cwd(); | |
fs.readdir(cwd, function(err, files) { | |
if(err){ | |
console.log(err); | |
return; | |
} | |
var last = files.length; | |
for(var i=0; i<last; ++i){ | |
try { | |
var file = cwd + '/' + files[i]; | |
var xml = fs.readFileSync(file, 'utf8'); | |
var json = parser.toJson(xml); | |
var newFile = cwd + '/json/' + files[i] + '.json'; | |
fs.writeFileSync(newFile, json); | |
} catch(e) { | |
console.log('failed to convert ' + file + ' to: ' + newFile + ' because: ' + e); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment