This repository was archived by the owner on Aug 15, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathsaxparser.js
More file actions
90 lines (75 loc) · 2.57 KB
/
Copy pathsaxparser.js
File metadata and controls
90 lines (75 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var EventEmitter, KDSaxParser,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
EventEmitter = require('microemitter').EventEmitter;
module.exports = KDSaxParser = (function(_super) {
var createErr, createSaxParser;
__extends(KDSaxParser, _super);
function KDSaxParser(options) {
var _ref, _ref1;
if (options.api != null) {
this.api = options.api, this.prefix = options.prefix;
}
if ((_ref = this.api) == null) {
this.api = options;
}
if ((_ref1 = this.prefix) == null) {
this.prefix = 'KD';
}
this.parser = createSaxParser({
onStartDocument: this.bound('emit', 'start'),
onEndDocument: this.bound('emit', 'end'),
onStartElementNS: this.bound('emit', 'elementstart'),
onEndElementNS: this.bound('emit', 'elementend'),
onCharacters: this.bound('emit', 'characters'),
onCdata: this.bound('emit', 'cdata'),
onComment: this.bound('emit', 'comment'),
onWarning: this.bound('warn'),
onError: this.bound('error')
});
}
createSaxParser = function(handlers) {
var SaxParser,
_this = this;
SaxParser = require('node-xml').SaxParser;
return new SaxParser(function(cb) {
var ev, handler, _results;
_results = [];
for (ev in handlers) {
if (!__hasProp.call(handlers, ev)) continue;
handler = handlers[ev];
_results.push(cb[ev](handler));
}
return _results;
});
};
createErr = function(message) {
if ('string' === typeof message) {
return new Error(message);
}
return message;
};
KDSaxParser.prototype.warn = function(message) {
return this.emit('warning', createErr(message));
};
KDSaxParser.prototype.error = function(message) {
return this.emit('error', createErr(message));
};
KDSaxParser.prototype.emit = function() {
KDSaxParser.__super__.emit.apply(this, arguments);
return console.log(arguments);
};
KDSaxParser.prototype.pause = function() {
return this.parser.pause();
};
KDSaxParser.prototype.resume = function() {
return this.parser.resume();
};
KDSaxParser.prototype.bound = require('koding-bound');
KDSaxParser.prototype.parse = function(xmlStr) {
var parser;
parser = this.parser;
return this.parser.parseString(xmlStr);
};
return KDSaxParser;
})(EventEmitter);