xml2js
Advanced tools
Comparing version 0.4.1 to 0.4.2
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.6.3 | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
@@ -3,0 +3,0 @@ var xml2js; |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.6.3 | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
@@ -3,0 +3,0 @@ var prefixMatch; |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.6.3 | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
@@ -223,4 +223,3 @@ var bom, builder, events, isEmpty, processName, processors, sax, | ||
Parser.prototype.reset = function() { | ||
var attrkey, charkey, err, ontext, stack, | ||
_this = this; | ||
var attrkey, charkey, ontext, stack; | ||
this.removeAllListeners(); | ||
@@ -232,9 +231,12 @@ this.saxParser = sax.parser(this.options.strict, { | ||
}); | ||
err = false; | ||
this.saxParser.onerror = function(error) { | ||
if (!err) { | ||
err = true; | ||
return _this.emit("error", error); | ||
} | ||
}; | ||
this.saxParser.errThrown = false; | ||
this.saxParser.onerror = (function(_this) { | ||
return function(error) { | ||
_this.saxParser.resume(); | ||
if (!_this.saxParser.errThrown) { | ||
_this.saxParser.errThrown = true; | ||
return _this.emit("error", error); | ||
} | ||
}; | ||
})(this); | ||
this.EXPLICIT_CHARKEY = this.options.explicitCharkey; | ||
@@ -245,119 +247,128 @@ this.resultObject = null; | ||
charkey = this.options.charkey; | ||
this.saxParser.onopentag = function(node) { | ||
var key, newValue, obj, processedKey, _ref; | ||
obj = {}; | ||
obj[charkey] = ""; | ||
if (!_this.options.ignoreAttrs) { | ||
_ref = node.attributes; | ||
for (key in _ref) { | ||
if (!__hasProp.call(_ref, key)) continue; | ||
if (!(attrkey in obj) && !_this.options.mergeAttrs) { | ||
obj[attrkey] = {}; | ||
this.saxParser.onopentag = (function(_this) { | ||
return function(node) { | ||
var key, newValue, obj, processedKey, _ref; | ||
obj = {}; | ||
obj[charkey] = ""; | ||
if (!_this.options.ignoreAttrs) { | ||
_ref = node.attributes; | ||
for (key in _ref) { | ||
if (!__hasProp.call(_ref, key)) continue; | ||
if (!(attrkey in obj) && !_this.options.mergeAttrs) { | ||
obj[attrkey] = {}; | ||
} | ||
newValue = node.attributes[key]; | ||
processedKey = _this.options.attrNameProcessors ? processName(_this.options.attrNameProcessors, key) : key; | ||
if (_this.options.mergeAttrs) { | ||
_this.assignOrPush(obj, processedKey, newValue); | ||
} else { | ||
obj[attrkey][processedKey] = newValue; | ||
} | ||
} | ||
newValue = node.attributes[key]; | ||
processedKey = _this.options.attrNameProcessors ? processName(_this.options.attrNameProcessors, key) : key; | ||
if (_this.options.mergeAttrs) { | ||
_this.assignOrPush(obj, processedKey, newValue); | ||
} else { | ||
obj[attrkey][processedKey] = newValue; | ||
} | ||
} | ||
} | ||
obj["#name"] = _this.options.tagNameProcessors ? processName(_this.options.tagNameProcessors, node.name) : node.name; | ||
if (_this.options.xmlns) { | ||
obj[_this.options.xmlnskey] = { | ||
uri: node.uri, | ||
local: node.local | ||
}; | ||
} | ||
return stack.push(obj); | ||
}; | ||
this.saxParser.onclosetag = function() { | ||
var cdata, emptyStr, node, nodeName, obj, old, s, xpath; | ||
obj = stack.pop(); | ||
nodeName = obj["#name"]; | ||
delete obj["#name"]; | ||
cdata = obj.cdata; | ||
delete obj.cdata; | ||
s = stack[stack.length - 1]; | ||
if (obj[charkey].match(/^\s*$/) && !cdata) { | ||
emptyStr = obj[charkey]; | ||
delete obj[charkey]; | ||
} else { | ||
if (_this.options.trim) { | ||
obj[charkey] = obj[charkey].trim(); | ||
obj["#name"] = _this.options.tagNameProcessors ? processName(_this.options.tagNameProcessors, node.name) : node.name; | ||
if (_this.options.xmlns) { | ||
obj[_this.options.xmlnskey] = { | ||
uri: node.uri, | ||
local: node.local | ||
}; | ||
} | ||
if (_this.options.normalize) { | ||
obj[charkey] = obj[charkey].replace(/\s{2,}/g, " ").trim(); | ||
return stack.push(obj); | ||
}; | ||
})(this); | ||
this.saxParser.onclosetag = (function(_this) { | ||
return function() { | ||
var cdata, emptyStr, err, node, nodeName, obj, old, s, xpath; | ||
obj = stack.pop(); | ||
nodeName = obj["#name"]; | ||
delete obj["#name"]; | ||
cdata = obj.cdata; | ||
delete obj.cdata; | ||
s = stack[stack.length - 1]; | ||
if (obj[charkey].match(/^\s*$/) && !cdata) { | ||
emptyStr = obj[charkey]; | ||
delete obj[charkey]; | ||
} else { | ||
if (_this.options.trim) { | ||
obj[charkey] = obj[charkey].trim(); | ||
} | ||
if (_this.options.normalize) { | ||
obj[charkey] = obj[charkey].replace(/\s{2,}/g, " ").trim(); | ||
} | ||
if (Object.keys(obj).length === 1 && charkey in obj && !_this.EXPLICIT_CHARKEY) { | ||
obj = obj[charkey]; | ||
} | ||
} | ||
if (Object.keys(obj).length === 1 && charkey in obj && !_this.EXPLICIT_CHARKEY) { | ||
obj = obj[charkey]; | ||
if (isEmpty(obj)) { | ||
obj = _this.options.emptyTag !== void 0 ? _this.options.emptyTag : emptyStr; | ||
} | ||
} | ||
if (isEmpty(obj)) { | ||
obj = _this.options.emptyTag !== void 0 ? _this.options.emptyTag : emptyStr; | ||
} | ||
if (_this.options.validator != null) { | ||
xpath = "/" + ((function() { | ||
var _i, _len, _results; | ||
_results = []; | ||
for (_i = 0, _len = stack.length; _i < _len; _i++) { | ||
node = stack[_i]; | ||
_results.push(node["#name"]); | ||
if (_this.options.validator != null) { | ||
xpath = "/" + ((function() { | ||
var _i, _len, _results; | ||
_results = []; | ||
for (_i = 0, _len = stack.length; _i < _len; _i++) { | ||
node = stack[_i]; | ||
_results.push(node["#name"]); | ||
} | ||
return _results; | ||
})()).concat(nodeName).join("/"); | ||
try { | ||
obj = _this.options.validator(xpath, s && s[nodeName], obj); | ||
} catch (_error) { | ||
err = _error; | ||
_this.emit("error", err); | ||
} | ||
return _results; | ||
})()).concat(nodeName).join("/"); | ||
try { | ||
obj = _this.options.validator(xpath, s && s[nodeName], obj); | ||
} catch (_error) { | ||
err = _error; | ||
_this.emit("error", err); | ||
} | ||
} | ||
if (_this.options.explicitChildren && !_this.options.mergeAttrs && typeof obj === 'object') { | ||
node = {}; | ||
if (_this.options.attrkey in obj) { | ||
node[_this.options.attrkey] = obj[_this.options.attrkey]; | ||
delete obj[_this.options.attrkey]; | ||
if (_this.options.explicitChildren && !_this.options.mergeAttrs && typeof obj === 'object') { | ||
node = {}; | ||
if (_this.options.attrkey in obj) { | ||
node[_this.options.attrkey] = obj[_this.options.attrkey]; | ||
delete obj[_this.options.attrkey]; | ||
} | ||
if (!_this.options.charsAsChildren && _this.options.charkey in obj) { | ||
node[_this.options.charkey] = obj[_this.options.charkey]; | ||
delete obj[_this.options.charkey]; | ||
} | ||
if (Object.getOwnPropertyNames(obj).length > 0) { | ||
node[_this.options.childkey] = obj; | ||
} | ||
obj = node; | ||
} | ||
if (!_this.options.charsAsChildren && _this.options.charkey in obj) { | ||
node[_this.options.charkey] = obj[_this.options.charkey]; | ||
delete obj[_this.options.charkey]; | ||
if (stack.length > 0) { | ||
return _this.assignOrPush(s, nodeName, obj); | ||
} else { | ||
if (_this.options.explicitRoot) { | ||
old = obj; | ||
obj = {}; | ||
obj[nodeName] = old; | ||
} | ||
_this.resultObject = obj; | ||
return _this.emit("end", _this.resultObject); | ||
} | ||
if (Object.getOwnPropertyNames(obj).length > 0) { | ||
node[_this.options.childkey] = obj; | ||
}; | ||
})(this); | ||
ontext = (function(_this) { | ||
return function(text) { | ||
var s; | ||
s = stack[stack.length - 1]; | ||
if (s) { | ||
s[charkey] += text; | ||
return s; | ||
} | ||
obj = node; | ||
} | ||
if (stack.length > 0) { | ||
return _this.assignOrPush(s, nodeName, obj); | ||
} else { | ||
if (_this.options.explicitRoot) { | ||
old = obj; | ||
obj = {}; | ||
obj[nodeName] = old; | ||
}; | ||
})(this); | ||
this.saxParser.ontext = ontext; | ||
return this.saxParser.oncdata = (function(_this) { | ||
return function(text) { | ||
var s; | ||
s = ontext(text); | ||
if (s) { | ||
return s.cdata = true; | ||
} | ||
_this.resultObject = obj; | ||
return _this.emit("end", _this.resultObject); | ||
} | ||
}; | ||
ontext = function(text) { | ||
var s; | ||
s = stack[stack.length - 1]; | ||
if (s) { | ||
s[charkey] += text; | ||
return s; | ||
} | ||
}; | ||
this.saxParser.ontext = ontext; | ||
return this.saxParser.oncdata = function(text) { | ||
var s; | ||
s = ontext(text); | ||
if (s) { | ||
return s.cdata = true; | ||
} | ||
}; | ||
}; | ||
})(this); | ||
}; | ||
Parser.prototype.parseString = function(str, cb) { | ||
var err; | ||
if ((cb != null) && typeof cb === "function") { | ||
@@ -389,3 +400,11 @@ this.on("end", function(result) { | ||
} | ||
return this.saxParser.write(bom.stripBOM(str.toString())).close(); | ||
try { | ||
return this.saxParser.write(bom.stripBOM(str.toString())).close(); | ||
} catch (_error) { | ||
err = _error; | ||
if (!this.saxParser.errThrown) { | ||
this.emit('error', err); | ||
return this.saxParser.errThrown = true; | ||
} | ||
} | ||
}; | ||
@@ -392,0 +411,0 @@ |
@@ -6,3 +6,3 @@ { | ||
"homepage" : "https://github.com/Leonidas-from-XIV/node-xml2js", | ||
"version" : "0.4.1", | ||
"version" : "0.4.2", | ||
"author" : "Marek Kubica <marek@xivilization.net> (http://xivilization.net)", | ||
@@ -32,3 +32,4 @@ "contributors" : [ | ||
"Camille Reynders <info@creynders.be> (http://www.creynders.be/)", | ||
"Taylor Gautier (https://github.com/tsgautier)" | ||
"Taylor Gautier (https://github.com/tsgautier)", | ||
"Todd Bryan (https://github.com/toddrbryan)" | ||
], | ||
@@ -51,4 +52,4 @@ "main" : "./lib/xml2js", | ||
"devDependencies" : { | ||
"coffee-script" : ">=1.6.3", | ||
"zap" : ">=0.2.5", | ||
"coffee-script" : ">=1.7.1", | ||
"zap" : ">=0.2.6", | ||
"docco" : ">=0.6.2", | ||
@@ -55,0 +56,0 @@ "diff" : ">=1.0.8" |
@@ -281,3 +281,3 @@ node-xml2js | ||
* `rootName` (default `root`): root element name to be used in case | ||
`explicitiRoot` is `false` or to override the root element name. | ||
`explicitRoot` is `false` or to override the root element name. | ||
* `renderOpts` (default `{ 'pretty': true, 'indent': ' ', 'newline': '\n' }`): | ||
@@ -284,0 +284,0 @@ Rendering options for xmlbuilder-js. |
101902
16
459