Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
simple-xml-reader
Advanced tools
A utility to read xml files through NodeJS Stream.
npm i simple-xml-reader --save
const { Writable } = require('stream')
const fs = require('fs')
const { xmlParser } = require('simple-xml-reader')
const write = (fn) => {
return new Writable({
objectMode: true,
write (chunk, _, callback) {
fn(chunk)
callback()
}
})
}
fs.createReadStream('path to xml file'))
.pipe(xmlParser())
.pipe(write((node) => {
console.log('XML Node', node)
}))
The each xml tag readed, the transform stream will generate a JavaScript object to represent it. The created object has the following structure:
{
"parent": {...},
"name": "node name",
"attrs": { node attributes },
"text": { node text },
"children": [{ children nodes } ...]
}
If you have a very large XML file with many nodes and do not need the relationship between them, you can modify the object created after creation to remove the relationship between the child and parent nodes. This strategy is useful for avoiding excessive memory consumption. See the example below that removes the links between the nodes:
...
fs.createReadStream('path to xml file'))
.pipe(xmlParser({
mapElement: (e) => {
e.parent = null // remove the link with parent node
e.children = [] // remove the links with children nodes
return e
}
}))
.pipe(write((node) => {
console.log('XML Node', node)
}))
...
FAQs
Utility for load xml files with stream
The npm package simple-xml-reader receives a total of 12 weekly downloads. As such, simple-xml-reader popularity was classified as not popular.
We found that simple-xml-reader 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.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.