score:1

You can use the following example as a guide. This requires NPM package xml-parser as a dependency.

var xmlDoc = [
  {
    type: 'element',
    tagName: '?xml',
    attributes: {
      version: '1.0',
      encoding: 'UTF-8'
    },
    childNodes: [],
    innerXML: '>',
    closing: false,
    closingChar: '?'
  },
  {
    type: 'element',
    tagName: 'root',
    attributes: {},
    childNodes: [
      {
        type: 'text',
        text: 'Root Element'
      }
    ],
    innerXML: 'Root Element',
    closing: true,
    closingChar: null
  }
]
 
var xmlStr = xml.stringify(xmlDoc, 2); // 2 spaces
 
console.log(xmlStr);


Related Query

More Query from same tag