aboutsummaryrefslogtreecommitdiff
path: root/cordova/node_modules/elementtree/lib/parsers
diff options
context:
space:
mode:
Diffstat (limited to 'cordova/node_modules/elementtree/lib/parsers')
-rwxr-xr-xcordova/node_modules/elementtree/lib/parsers/index.js1
-rwxr-xr-xcordova/node_modules/elementtree/lib/parsers/sax.js56
2 files changed, 57 insertions, 0 deletions
diff --git a/cordova/node_modules/elementtree/lib/parsers/index.js b/cordova/node_modules/elementtree/lib/parsers/index.js
new file mode 100755
index 0000000..5eac5c8
--- /dev/null
+++ b/cordova/node_modules/elementtree/lib/parsers/index.js
@@ -0,0 +1 @@
+exports.sax = require('./sax');
diff --git a/cordova/node_modules/elementtree/lib/parsers/sax.js b/cordova/node_modules/elementtree/lib/parsers/sax.js
new file mode 100755
index 0000000..69b0a59
--- /dev/null
+++ b/cordova/node_modules/elementtree/lib/parsers/sax.js
@@ -0,0 +1,56 @@
+var util = require('util');
+
+var sax = require('sax');
+
+var TreeBuilder = require('./../treebuilder').TreeBuilder;
+
+function XMLParser(target) {
+ this.parser = sax.parser(true);
+
+ this.target = (target) ? target : new TreeBuilder();
+
+ this.parser.onopentag = this._handleOpenTag.bind(this);
+ this.parser.ontext = this._handleText.bind(this);
+ this.parser.oncdata = this._handleCdata.bind(this);
+ this.parser.ondoctype = this._handleDoctype.bind(this);
+ this.parser.oncomment = this._handleComment.bind(this);
+ this.parser.onclosetag = this._handleCloseTag.bind(this);
+ this.parser.onerror = this._handleError.bind(this);
+}
+
+XMLParser.prototype._handleOpenTag = function(tag) {
+ this.target.start(tag.name, tag.attributes);
+};
+
+XMLParser.prototype._handleText = function(text) {
+ this.target.data(text);
+};
+
+XMLParser.prototype._handleCdata = function(text) {
+ this.target.data(text);
+};
+
+XMLParser.prototype._handleDoctype = function(text) {
+};
+
+XMLParser.prototype._handleComment = function(comment) {
+};
+
+XMLParser.prototype._handleCloseTag = function(tag) {
+ this.target.end(tag);
+};
+
+XMLParser.prototype._handleError = function(err) {
+ throw err;
+};
+
+XMLParser.prototype.feed = function(chunk) {
+ this.parser.write(chunk);
+};
+
+XMLParser.prototype.close = function() {
+ this.parser.close();
+ return this.target.close();
+};
+
+exports.XMLParser = XMLParser;