Convert JavaScript Object To XML String – toXML.js

Category: Javascript | February 20, 2023
Views Total:1,585 views
Official Page:Go to website
Last Update:February 20, 2023


Convert JavaScript Object To XML String – toXML.js


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">

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.



  • v0.1.9

You Might Be Interested In:

Leave a Reply