Convert JavaScript Object To XML String – toXML.js

Category: Javascript | February 20, 2023
Author:kawanet
Views Total:3,428 views
Official Page:Go to website
Last Update:February 20, 2023
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.

Changelog:

02/20/2023

  • v0.1.9

You Might Be Interested In:


Leave a Reply