
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Sometimes you need to parse large XML files to extract some repetitive element and process each of them sequentially as a NodeJS Stream. Existing solutions are either too complex, using native libraries or too low-level, so I made this one for those who need pretty simple stream-based XML parsing. For now, it's based on sax module and allows you to simply specify path to elements that you would like to extract via simple dot notation (not XPath!)
Use it if you don't need extra performance and don't want to deal with low-level details of using sax library.
If you need something more complicated, consider using sax or something else directly
Imagine you have a large XML with following structure and you want to process each elt sequentially:
<root>
<elt foo="1">First element</elt>
<elt foo="2">Second element</elt>
<elt foo="3">Third element</elt>
<!-- Several more million of the rows -->
</root>
const fs = require('fs');
const { XmlStream } = require('xmlkit');
(async function () {
// Create stream pipeline
const input = fs.createReadStream('./10gbfile.xml');
const parser = new XmlStream('root.elt');
const xml = input.pipe(parser);
// Iterate using async iterable
for await (const chunk of xml) {
// each chunk will contain an xml string representing current elt node
console.log(chunk);
}
// Or iterate using stream interface
xml
.on('data', (chunk) => console.log(chunk))
.on('end', () => console.log('all xml loaded'));
// Or just pipe to other file
xml.pipe(fs.createWriteStream('./result.xml'));
})();
A constructor that creates parser instance.
Takes a string specifying selector for extracting elements in dot notation as a
first parameter, example: root.elt
. root and elt is an en element name
ONLY this, simple format is supported, this is NOT an XPath, so only element
selectors is supported.
Event emitted for each of the extracted nodes specified by selector passed in constructor. Chunk is just a string containing XML data of the needed element, which enables you to use any of your favorite XML parser to further process the chunk.
Working with XML is pain in NodeJS, so if this package gains any substantil amount of popularity, I will consider adding other useful XML tools here, since package name is very flexible and fits for anything related to XML.
Feel free to create discussion or file PR
FAQs
xml tools
The npm package xmlkit receives a total of 510 weekly downloads. As such, xmlkit popularity was classified as not popular.
We found that xmlkit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.