/usr/lib/nodejs/ltx/parse.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 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 91 92 93 94 95 96 97 | var events = require('events');
var util = require('util');
exports.availableSaxParsers = [];
exports.bestSaxParser = null;
['./sax_expat.js', './sax_ltx.js', /*'./sax_easysax.js', './sax_node-xml.js',*/ './sax_saxjs.js'].forEach(function(modName) {
var mod;
try {
mod = require(modName);
} catch (e) {
/* Silently missing libraries drop; for debug:
console.error(e.stack || e);
*/
}
if (mod) {
exports.availableSaxParsers.push(mod);
if (!exports.bestSaxParser)
exports.bestSaxParser = mod;
}
});
var element = require('./element');
exports.Parser = function(saxParser) {
events.EventEmitter.call(this);
var that = this;
var parserMod = saxParser || exports.bestSaxParser;
if (!parserMod)
throw new Error("No SAX parser available");
this.parser = new parserMod();
var el;
this.parser.addListener('startElement', function(name, attrs) {
var child = new element.Element(name, attrs);
if (!el) {
el = child;
} else {
el = el.cnode(child);
}
});
this.parser.addListener('endElement', function(name) {
if (!el) {
/* Err */
} else if (el && name == el.name) {
if (el.parent)
el = el.parent;
else if (!that.tree) {
that.tree = el;
el = undefined;
}
}
});
this.parser.addListener('text', function(str) {
if (el)
el.t(str);
});
this.parser.addListener('error', function(e) {
that.error = e;
that.emit('error', e);
});
};
util.inherits(exports.Parser, events.EventEmitter);
exports.Parser.prototype.write = function(data) {
this.parser.write(data);
};
exports.Parser.prototype.end = function(data) {
this.parser.end(data);
if (!this.error) {
if (this.tree)
this.emit('tree', this.tree);
else
this.emit('error', new Error('Incomplete document'));
}
};
exports.parse = function(data, saxParser) {
var p = new exports.Parser(saxParser);
var result = null, error = null;
p.on('tree', function(tree) {
result = tree;
});
p.on('error', function(e) {
error = e;
});
p.write(data);
p.end();
if (error)
throw error;
else
return result;
};
|