Installations
npm install xml-stream-saxes
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
10.22.1
NPM Version
6.14.6
Score
72
Supply Chain
97.6
Quality
74.4
Maintenance
100
Vulnerability
98.9
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
validate.email 🚀
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Developer
maxsivanov
Download Statistics
Total Downloads
785
Last Day
17
Last Week
17
Last Month
20
Last Year
196
GitHub Statistics
MIT License
111 Commits
2 Forks
1 Branches
1 Contributors
Updated on Jun 09, 2021
Bundle Size
37.02 kB
Minified
10.89 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.4.9
Package Id
xml-stream-saxes@0.4.9
Unpacked Size
32.14 kB
Size
9.79 kB
File Count
15
NPM Version
6.14.6
Node Version
10.22.1
Total Downloads
Cumulative downloads
Total Downloads
785
Last Day
0%
17
Compared to previous day
Last Week
0%
17
Compared to previous week
Last Month
-9.1%
20
Compared to previous month
Last Year
83.2%
196
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
Dev Dependencies
1
XmlStream-Saxes
XmlStream is a Node.js XML stream parser and editor, based on saxes (libexpat SAX-like parser binding).
Fork of xml-stream
project which is unmaintained
$ npm install xml-stream-saxes
Rationale
When working with large XML files, it is probably a bad idea to use an XML to JavaScript object converter, or simply buffer the whole document in memory. Then again, a typical SAX parser might be too low-level for some tasks (and often a real pain).
This is why we've rolled our own stream parser that tries to address these shortcomings. It processes an XML stream chunk by chunk and fires events only for nodes of interest, matching them with CSS-like selectors.
Events
Supported events:
data
on outgoing data chunk,end
when parsing has ended,startElement[: selector]
on opening tag for selector match,updateElement[: selector]
on finished node for selector match with its contents buffered,endElement[: selector]
on closing tag for selector match,text[: selector]
on tag text for selector match.
When adding listeners for startElement
, updateElement
, and text
the
callback can modify the provided node, before it is sent to the consumer.
Selector syntax is CSS-like and currently supports:
ancestor descendant
parent > child
Take a look at the examples for more information.
Element Node
Each of the four node events has a callback with one argument. When parsing, this argument is set to the current matched node. Having a chunk of XML like this:
1<item id="123" type="common"> 2 <title>Item Title</title> 3 <description>Description of this item.</description> 4 (text) 5</item>
The structure of the item element node would be:
1{ 2 title: 'Item Title', 3 description: 'Description of this item.', 4 '$': { 5 'id': '123', 6 'type': 'common' 7 }, 8 '$name': 'item', 9 '$text': '(text)' 10}
Naturally, element text and child elements wouldn't be known until discovered in the stream, so the structure may differ across events. The complete structure as displayed should be available on updateElement. The $name is not available on endElement.
Collecting Children
It is sometimes required to select elements that have many children with one and the same name. Like this XML:
1<item id="1"> 2 <subitem>one</subitem> 3 <subitem>two</subitem> 4</item> 5<item id="2"> 6 <subitem>three</subitem> 7 <subitem>four</subitem> 8 <subitem>five</subitem> 9</item>
By default, parsed element node contains children as properties. In the case of several children with same names, the last one would overwrite others. To collect all of subitem elements in an array use collect:
1xml.collect('subitem'); 2xml.on('endElement: item', function(item) { 3 console.log(item); 4})
Preserving Elements and Text
By default, element text is returned as one concatenated string. In this XML:
1<item> 2 one <a>1</a> 3 two <b>2</b> 4</item>
The value of $text for item would be: one 1 two 2
without any
indication of the order of element a, element b, and text parts.
To preserve this order:
1xml.preserve('item'); 2xml.on('endElement: item', function(item) { 3 console.log(item); 4})
Pause and resume parsing
If you want parsing to pause (for example, until some asynchronous operation of yours is finished), you can pause and resume XML parsing:
1xml.pause(); 2myAsyncFunction( function() { 3 xml.resume(); 4});
Beware that resume() must not be called from within a handler callback.

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
no effort to earn an OpenSSF best practices badge detected
Score
3
/10
Last Scanned on 2025-03-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More