/usr/lib/nodejs/ltx/sax_expat.js is in node-ltx 0.2.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | var util = require('util');
var events = require('events');
var expat = require('node-expat');
var SaxExpat = module.exports = function SaxExpat() {
events.EventEmitter.call(this);
this.parser = new expat.Parser('UTF-8');
var that = this;
this.parser.on('startElement', function(name, attrs) {
that.emit('startElement', name, attrs);
});
this.parser.on('endElement', function(name) {
that.emit('endElement', name);
});
this.parser.on('text', function(str) {
that.emit('text', str);
});
// TODO: other events, esp. entityDecl (billion laughs!)
};
util.inherits(SaxExpat, events.EventEmitter);
SaxExpat.prototype.write = function(data) {
if (!this.parser.parse(data, false)) {
this.emit('error', new Error(this.parser.getError()));
// Premature error thrown,
// disable all functionality:
this.write = function() { };
this.end = function() { };
}
};
SaxExpat.prototype.end = function(data) {
if (!this.parser.parse('', true))
this.emit('error', new Error(this.parser.getError()));
else
this.emit('end');
};
|