Gathering detailed insights and metrics for saxen
Gathering detailed insights and metrics for saxen
Gathering detailed insights and metrics for saxen
Gathering detailed insights and metrics for saxen
A tiny, super fast, namespace aware, sax-style XML parser.
npm install saxen
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.6
Supply Chain
99.6
Quality
76.2
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
13,314,418
Last Day
4,730
Last Week
114,751
Last Month
445,676
Last Year
4,456,647
MIT License
20 Stars
333 Commits
4 Forks
4 Watchers
1 Branches
1 Contributors
Updated on Jul 20, 2025
Latest Version
10.0.0
Package Id
saxen@10.0.0
Unpacked Size
146.14 kB
Size
25.53 kB
File Count
7
NPM Version
10.2.4
Node Version
20.11.1
Published on
Mar 05, 2024
Cumulative downloads
Total Downloads
7
/saxen/
parserA tiny, super fast, namespace aware sax-style XML parser written in plain JavaScript.
2.6Kb
minified + gzipped)1var { 2 Parser 3} = require('saxen'); 4 5var parser = new Parser(); 6 7// enable namespace parsing: element prefixes will 8// automatically adjusted to the ones configured here 9// elements in other namespaces will still be processed 10parser.ns({ 11 'http://foo': 'foo', 12 'http://bar': 'bar' 13}); 14 15parser.on('openTag', function(elementName, attrGetter, decodeEntities, selfClosing, getContext) { 16 17 elementName; 18 // with prefix, i.e. foo:blub 19 20 var attrs = attrGetter(); 21 // { 'bar:aa': 'A', ... } 22}); 23 24parser.parse('<blub xmlns="http://foo" xmlns:bar="http://bar" bar:aa="A" />');
We support the following parse hooks:
openTag(elementName, attrGetter, decodeEntities, selfClosing, contextGetter)
closeTag(elementName, decodeEntities, selfClosing, contextGetter)
error(err, contextGetter)
warn(warning, contextGetter)
text(value, decodeEntities, contextGetter)
cdata(value, contextGetter)
comment(value, decodeEntities, contextGetter)
attention(str, decodeEntities, contextGetter)
question(str, contextGetter)
In contrast to error
, warn
receives recoverable errors, such as malformed attributes.
In proxy mode, openTag
and closeTag
a view of the current element replaces the raw element name. In addition element attributes are not passed as a getter to openTag
. Instead, they get exposed via the element.attrs
:
openTag(element, decodeEntities, selfClosing, contextGetter)
closeTag(element, selfClosing, contextGetter)
In namespace mode, the parser will adjust tag and attribute namespace prefixes before
passing the elements name to openTag
or closeTag
. To do that, you need to
configure default prefixes for wellknown namespaces:
1parser.ns({ 2 'http://foo': 'foo', 3 'http://bar': 'bar' 4});
To skip the adjustment and still process namespace information:
1parser.ns();
In this mode, the first argument passed to openTag
and closeTag
is an object that exposes more internal XML parse state. This needs to be explicity enabled by instantiating the parser with { proxy: true }
.
1// instantiate parser with proxy=true 2var parser = new Parser({ proxy: true }); 3 4parser.ns({ 5 'http://foo-ns': 'foo' 6}); 7 8parser.on('openTag', function(el, decodeEntities, selfClosing, getContext) { 9 el.originalName; // root 10 el.name; // foo:root 11 el.attrs; // { 'xmlns:foo': ..., id: '1' } 12 el.ns; // { xmlns: 'foo', foo: 'foo', foo$uri: 'http://foo-ns' } 13}); 14 15parser.parse('<root xmlns:foo="http://foo-ns" id="1" />')
Proxy mode comes with a performance penelty of roughly five percent.
Caution! For performance reasons the exposed element is a simple view into the current parser state. Because of that, it will change with the parser advancing and cannot be cached. If you would like to retain a persistent copy of the values, create a shallow clone:
1parser.on('openTag', function(el) { 2 var copy = Object.assign({}, el); 3 // copy, ready to keep around 4});
/saxen/
lacks some features known in other XML parsers such as sax-js:
...and that is ok ❤.
We build on the awesome work done by easysax.
/saxen/
is named after Sachsen, a federal state of Germany. So geht sächsisch!
MIT
No vulnerabilities found.
Last Day
40.8%
4,730
Compared to previous day
Last Week
10%
114,751
Compared to previous week
Last Month
0.6%
445,676
Compared to previous month
Last Year
51.5%
4,456,647
Compared to previous year