
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
node-expat-meteor
Advanced tools
You use node.js for speed? You process XML streams? Then you want the fastest XML parser: libexpat!
A stupid speed test is supplied in bench.js
. We measure how many
25-byte elements a SAX parser can process:
These numbers were recorded on a Core 2 2400 MHz.
Install node-expat:
npm i node-expat
Important events emitted by a parser:
(function () {
"use strict";
var expat = require('node-expat')
, parser
;
parser = new expat.Parser("UTF-8");
parser.on('startElement', function (name, attrs) {
console.log(name, attrs);
});
parser.on('endElement', function (name) {
console.log(name);
});
parser.on('text', function (text) {
console.log(text);
});
parser.on('error', function (err) {
console.error(err);
});
parser.write("<html><head><title>Hello World</title></head><body><p>Foobar</p></body></html>");
}());
Use test.js
for reference.
#on('startElement' function (name, attrs) {})
#on('endElement' function (name) {})
#on('text' function (text) {})
#on('processingInstruction', function (target, data) {})
#on('comment', function (s) {})
#on('xmlDecl', function (version, encoding, standalone) {})
#on('startCdata', function () {})
#on('startCdata', function () {})
#on('endCdata', function () {})
#on('entityDecl', function (entityName, isParameterEntity, value, base, systemId, publicId, notationName) {})
#on('error', function (e) {})
#stop()
pauses#resume()
resumesWe don't emit an error event because libexpat doesn't use a callback
either. Instead, check that parse()
returns true
. A descriptive
string can be obtained via getError()
to provide user feedback.
Alternatively, use the Parser like a node Stream. write()
will emit
error events.
A word about special parsing of xmlns: this is not neccessary in a bare SAX parser like this, given that the DOM replacement you are using (if any) is not relevant to the parser.
FAQs
Meteor binding for fast XML parsing.
We found that node-expat-meteor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.