Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Emits an error even for the sax event onerror.

  • Loading branch information...
commit a48e4a4bec2576e9b091c3210a5fe06ea99f538a 1 parent 7dddb3c
@SaltwaterC SaltwaterC authored
Showing with 17 additions and 1 deletion.
  1. +8 −1 lib/xml2js.js
  2. +9 −0 src/xml2js.coffee
View
9 lib/xml2js.js
@@ -13,7 +13,7 @@
exports.Parser = (function() {
__extends(Parser, events.EventEmitter);
function Parser(opts) {
- this.parseString = __bind(this.parseString, this); var key, options, stack, value;
+ this.parseString = __bind(this.parseString, this); var err, key, options, stack, value;
options = {
explicitCharkey: false,
trim: true,
@@ -28,6 +28,13 @@
trim: false,
normalize: false
});
+ err = false;
+ this.saxParser.onerror = __bind(function(error) {
+ if (!err) {
+ err = true;
+ return this.emit("error", error);
+ }
+ }, this);
this.EXPLICIT_CHARKEY = options.explicitCharkey;
this.resultObject = null;
stack = [];
View
9 src/xml2js.coffee
@@ -20,6 +20,15 @@ class exports.Parser extends events.EventEmitter
trim: false,
normalize: false
}
+
+ # emit one error event if the sax parser fails. this is mostly a hack, but
+ # the sax parser isn't state of the art either.
+ err = false
+ @saxParser.onerror = (error) =>
+ if ! err
+ err = true
+ @emit "error", error
+
# always use the '#' key, even if there are no subkeys
# setting this property by and is deprecated, yet still supported.
# better pass it as explicitCharkey option to the constructor
Please sign in to comment.
Something went wrong with that request. Please try again.