Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
node-expat
Advanced tools
Readme
You use Node.js for speed? You process XML streams? Then you want the fastest XML parser: libexpat!
npm install node-expat
Important events emitted by a parser:
(function () {
"use strict";
var expat = require('node-expat')
var 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 (error) {
console.error(error)
})
parser.write('<html><head><title>Hello World</title></head><body><p>Foobar</p></body></html>')
}())
#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('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 necessary in a bare SAX parser like this, given that the DOM replacement you are using (if any) is not relevant to the parser.
npm run benchmark
module | ops/sec | native | XML compliant | stream |
---|---|---|---|---|
sax-js | 99,412 | ☐ | ☑ | ☑ |
node-xml | 130,631 | ☐ | ☑ | ☑ |
libxmljs | 276,136 | ☑ | ☑ | ☐ |
node-expat | 322,769 | ☑ | ☑ | ☑ |
Higher is better.
npm install -g standard
npm test
If you fail to install node-expat as a dependency of node-xmpp, please update node-xmpp as it doesn't use node-expat anymore.
Dependencies for node-gyp
https://github.com/TooTallNate/node-gyp#installation
See https://github.com/astro/node-expat/issues/78 if you are getting errors about not finding nan.h
.
VCBUILD : error : project file 'node-expat\build\deps\libexpat\expat.vcproj' was not found or not a valid proj
ect file. [C:\Users\admin\AppData\Roaming\npm\node_modules\node-expat\build\bin
ding.sln]
Install Visual Studio C++ 2012 and run npm with the --msvs_version=2012
flag.
FAQs
NodeJS binding for fast XML parsing.
The npm package node-expat receives a total of 127,118 weekly downloads. As such, node-expat popularity was classified as popular.
We found that node-expat demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers 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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.