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.
basic-xml2json
Advanced tools
Readme
Simple parser to convert XML strings to JSON.
var xml2json = require('basic-xml2json');
This code is based off the xml-parser here: https://github.com/segmentio/xml-parser. Please see that page for details of the JSON output.
The parse function takes an XML string (mandatory) and an object describing the options (optional).
var json = xml2json.parse(xml, options);
Or
var json = xml2json.parse(xml);
removeNamespacePrefixes
Boolean, defaults to true. Set this to false if you want to retain xml namespace prefixes in the JSON output.
var options = { removeNamespacePrefixes: false };
Get an array of matching nodes under the specified parent node for the specified path.
var json = xml2json.parse(xml);
var nodes = xml2json.getChildNodes(json.root, ['Body','Response','Address']);
Get the first matching node under the specified parent node for the specified path.
var json = xml2json.parse(xml);
var address = xml2json.getChildNode(json.root, ['Body','Response','Address']);
Get the value of the first matching node under the specified parent node for the specified path. Encoded XML values will are decoded.
var json = xml2json.parse(xml);
var address = xml2json.getChildNode(json.root, ['Body','Response','Address']);
var suburb = xml2json.getContent(address, 'Suburb');
Or var suburb = xml2json.getContent(json.root, ['Body','Response','Address','Suburb']);
Just like getContent except that encoded XML values are not decoded.
var suburb = xml2json.getRawContent(json.root, ['Body','Response','Address','Suburb']);
Get an array of values for the matching nodes under the specified parent node for the specified path. Encoded XML values will are decoded.
var json = xml2json.parse(xml);
var suburbs = xml2json.getAllContent(json.root, ['Body','Response','Address','Suburb']);
Decode some text.
var decodedText = decodeXML(text);
Encode some text.
var encodedText = encodeXML(text);
Probably rarely useful, but if you have a situation where you need to match elements with different paths (but at the same depth) then you can use a wildcard match. For example:
<xmldoc>
<postalAddress>
<suburb>Brisbane</suburb>
</postalAddress>
<billingAddress>
<suburb>Sydney</suburb>
</billingAddress>
</xmldoc>
var json = xml2json.parse(xml);
var suburbs = xml2json.getAllContent(json.root, [xml2json.ANY, 'suburb']);
In this example, suburbs will be ['Brisbane','Sydney'].
FAQs
Basic parser to convert XML strings to JSON
The npm package basic-xml2json receives a total of 86 weekly downloads. As such, basic-xml2json popularity was classified as not popular.
We found that basic-xml2json 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.