Convert JavaScript Object To XML String – toXML.js

Category: Javascript | June 17, 2021
Author:kawanet
Views Total:326 views
Official Page:Go to website
Last Update:June 17, 2021
License:MIT

Preview:

Convert JavaScript Object To XML String – toXML.js

Description:

A tiny JS Objects to XML converter library that works with both browser and node.js.

How to use it:

1. Import the toXML.js.

// Browser
<script src="dist/to-xml.min.js"></script>

// Node
const toXML = require("to-xml").toXML;

2. Convert a JavaScript object to an XML string.

const data = {
  "xml": {
    "@css": "script",
    "javascript": {
      "html": "css"
    }
  }
};
const xml = toXML(data, null, 2);
// Output
<xml css="script">
  <javascript>
    <html>css</html>
  </javascript>
</xml>

3. Parameters:

  • value: The value to convert to an XML string.
  • replacer: A function that alters the behavior of the stringification process.
  • space: A String or Number object that’s used to insert white space into the output XML string for readability purposes. If this is a Number, it indicates the number of space characters to use as white space. If this is a String, the string is used as white space.

You Might Be Interested In:


Leave a Reply