Socket
Socket
Sign inDemoInstall

xml-js

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xml-js

A convertor between XML text and Javascript object / JSON text.


Version published
Weekly downloads
1.6M
decreased by-17.01%
Maintainers
1
Weekly downloads
 
Created

What is xml-js?

The xml-js npm package is a utility that provides methods to convert between XML and JSON format. It can also convert between XML and JavaScript objects. This package is useful when working with XML data in JavaScript environments where JSON is more easily manipulated.

What are xml-js's main functionalities?

XML to JSON Conversion

Converts an XML string to a JSON string. The options object can be used to customize the output.

const convert = require('xml-js');
const xml = '<note><to>User</to><from>Library</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>';
const options = {compact: true, ignoreComment: true, spaces: 4};
const result = convert.xml2json(xml, options);
console.log(result);

JSON to XML Conversion

Converts a JSON string to an XML string. The options object can be used to customize the output.

const convert = require('xml-js');
const json = '{"note":{"to":"User","from":"Library","heading":"Reminder","body":"Don't forget me this weekend!"}}';
const options = {compact: true, ignoreComment: true, spaces: 4};
const result = convert.json2xml(json, options);
console.log(result);

XML to JavaScript Object

Converts an XML string to a JavaScript object. The options object can be used to customize the output.

const convert = require('xml-js');
const xml = '<note><to>User</to><from>Library</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>';
const result = convert.xml2js(xml, {compact: true, spaces: 4});
console.log(result);

JavaScript Object to XML

Converts a JavaScript object to an XML string. The options object can be used to customize the output.

const convert = require('xml-js');
const jsObject = {
  note: {
    to: 'User',
    from: 'Library',
    heading: 'Reminder',
    body: 'Don't forget me this weekend!'
  }
};
const options = {compact: true, spaces: 4};
const result = convert.js2xml(jsObject, options);
console.log(result);

Other packages similar to xml-js

Keywords

FAQs

Package last updated on 03 Jul 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc