
Security News
New CVE Forecasting Tool Predicts 47,000 Disclosures in 2025
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
xml-mapping
Advanced tools
provide a bidirectionnal mapping between XML and JS data Structure (aka JSON)
It's native javascript implementation of a bidirectional converter between XML and JS data structure (aka JSON). You can convert any type of XML documents in an Javascript data structure. You can also do the reverse, converting a Javascript data structure in XML String. XML is still valid.
With npm do:
$ npm install xml-mapping
var XMLMapping = require('xml-mapping');
var json = XMLMapping.load('<key>value</key>');
var xml = XMLMapping.dump(json);
console.log(xml,json);
console.log(json);
Output:
<key>value</key> { key: { '$t': 'value' } }
The rules for converting XML to JSON are those used by Google in its GData protocol. More information here : http://code.google.com/apis/gdata/docs/json.html
Use nodeunit to run the tests.
$ npm install nodeunit
$ nodeunit test
Transform a string with XML in Javascript data structure (JSON). Return Object.
###Options
Warning : options break the symmetry. This means that the JSON generated may not reproduce the same XML
throwErrors
- boolean - Flag to throw errors of the SAX Parser ; default : falsenested
- boolean - Flag to ignore nested tags inside text : default : falsespecialChar
- string - Set the first character of XML tag ($t, $text, $cd, $cdata, $e, $element, $c, $comment); default : $longTag
- boolean - Use long names tags($text, $element, $cdata, $comment) rather than short names ($t, $cd, $e, $c); default : falsecomments
- boolean - Flag to ignore comments, if false all the comments will be ignored : default : trueparserInfos
- boolean - Flag to add some attributes generated by the parser (order, line, column, name), if true informations are inserted in the attributes list of all tags : default : falsevar xml = '<title>Title is <strong>important</strong></title>';
var json = XMLMapping.load(xml, { nested: true });
console.log(json);
// Should output:
// { title : { $t : 'Title is<strong>important</strong>', strong: { '$t': 'important' }} }
arrays
- array - an array of basic XPath strings that specify XML nodes that should be array, even when there is only one such node.var xml = '<key1>value1</key1><key2><key3>value3</key3></key2>';
var json = XMLMapping.load(xml, {
arrays: [
'/key1',
'/key2/key3'
]
});
console.log(json);
// Should output:
// (Note that value of key1 and key3 are arrays, as specified in options)
// {"key1":[{"$t":"value1"}],"key2":{"key3":[{"$t":"value3"}]}}
Transform a Javascript data structure (JSON) in XML string. Return String.
###Options
Warning : options break the symmetry. This means that the XML generated may not reproduce the same JSON
indent
- boolean - Flag to throw errors of the SAX Parser ; default : falseheader
- boolean - Flag to add XML header; default : falseversion
- string - Set version attribute of XML header (see header flag); default : 1.0encoding
- string - Set encoding attribute of XML header (see header flag); default : UTF-8specialChar
- string - Set the first character of XML tag ($t, $text, $cd, $cdata, $e, $element, $c, $comment); default : $Alias of load.
Alias of dump.
FAQs
provide a bidirectionnal mapping between XML and JS data Structure (aka JSON)
The npm package xml-mapping receives a total of 5,451 weekly downloads. As such, xml-mapping popularity was classified as popular.
We found that xml-mapping demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.