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.
@warerebel/datexparser
Advanced tools
Readme
An xml stream parser designed to make it easier to deal with large volumes of xml which are to be handled by a pipeline. Implemented in production as a datex2 parser accepting large volumes of traffic data in datex2, hence the name. Built upon xml-flow and is primarily a convenience wrapper around this module.
$ npm install @warerebel/datexparser`
Constructor accepts an options object detailed below, there are no mandatory options:
const options = {
tagsToPush: ["string"],
metaData: [{tag: "string", data: "string"}],
externals: [{tag: "string", event: "string"}]
}
The simplest example takes the following data.xml:
<data>
<item>
<name>item 1</name>
</item>
<item>
<name>item 2</name>
</item>
<dataobject>
<name>dataobject 1</name>
</dataobject>
</data>
and emits a "data" event for every "name":
const datexparser = require("@warerebel/datexparser");
const filestream = require("fs").createReadStream("data.xml", "utf8");
const options = {
tagsToPush: ["name"]
}
let myParser = new datexparser(options);
myParser.on("data", (data) => {
console.log(data.$text);
});
myParser.handleRequest(filestream, (error) => {
// callback is called when parsing is finished
});
Output:
item 1
item 2
dataobject 1
We might want to capture info elsewhere in the xml and emit it with specific matching tags.
<data>
<country>US</country>
<items>
<item>
<name>item 1</name>
</item>
<item>
<name>item 2</name>
</item>
<dataobject>
<name>dataobject 1</name>
</dataobject>
</items>
</data>
In the above data.xml we want dataobjects and items to be emitted with a country code. We add metaData
to options which is an array of objects with a target tag name and the meta data tag name to associate with it.
const datexparser = require("@warerebel/datexparser");
const filestream = require("fs").createReadStream("data.xml", "utf8");
const options = {
tagsToPush: ["item","dataobject"],
metaData:[{tag: "item",data: "country"},{tag: "dataobject",data: "country"}]
}
let myParser = new datexparser(options);
myParser.on("data", (data) => {
console.log(`Item named ${data.name} has country code ${data.country}`);
});
myParser.handleRequest(filestream, (error) => {
// callback is called when parsing is finished
});
Output:
Item named item 1 has country code US
Item named item 2 has country code US
Item named dataobject 1 has country code US
If we want to treat some data differently we can ask datexparser to emit a custom event for us to listen to rather than just emitting data events:
<data>
<country>US</country>
<items>
<item>
<name>item 1</name>
</item>
<item>
<name>item 2</name>
</item>
<dataobject>
<name>dataobject 1</name>
</dataobject>
</items>
</data>
const datexparser = require("@warerebel/datexparser");
const filestream = require("fs").createReadStream("data.xml", "utf8");
const options = {
tagsToPush: ["item"],
externals: [{tag: "dataobject", event: "dataobject"}]
}
let myParser = new datexparser(options);
myParser.on("data", (data) => {
console.log("Received data");
});
myParser.on("dataobject", (dataobject) => {
console.log("Received dataobject");
});
myParser.handleRequest(filestream, (error) => {
// callback is called when parsing is finished
});
Output
Received data
Received data
Received dataobject
FAQs
An xml parser to simplify handling high volume of xml streams
The npm package @warerebel/datexparser receives a total of 12 weekly downloads. As such, @warerebel/datexparser popularity was classified as not popular.
We found that @warerebel/datexparser 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
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.