Update to use v0.2.x of xml2js

This commit is contained in:
Tom Hughes 2013-02-10 20:46:12 +00:00
parent 55fbafe0d0
commit 48d89889fe
2 changed files with 8 additions and 5 deletions

View File

@ -25,8 +25,8 @@ fs.readFile(process.argv[2], 'utf-8', function(err, data) {
});
function addAttributes(obj) {
if (obj['@']) for (var key in obj['@']) obj[key] = obj['@'][key];
delete obj['@'];
if (obj['$']) for (var key in obj['$']) obj[key] = obj['$'][key];
delete obj['$'];
return obj;
}
@ -35,7 +35,10 @@ fs.readFile(process.argv[2], 'utf-8', function(err, data) {
else return obj;
}
var parser = new xml2js.Parser();
var parser = new xml2js.Parser({
explicitRoot: false,
explicitArray: false
});
parser.addListener('end', function(json) {
console.log(JSON.stringify(json, function(key, value) {
if (!key) {
@ -52,7 +55,7 @@ fs.readFile(process.argv[2], 'utf-8', function(err, data) {
else if (key === 'Datasource') {
value = addAttributes(value);
value.Parameter.forEach(function(parameter) {
value[parameter['@'].name] = parameter['#'];
value[parameter['$'].name] = parameter['_'];
});
delete value.Parameter;
return value;

View File

@ -37,7 +37,7 @@
"dependencies": {
"underscore": "~1.4.3",
"mapnik-reference": "~5.0.3",
"xml2js": "~0.1.13",
"xml2js": "~0.2.4",
"optimist": "~0.3.5"
},
"devDependencies": {