0.2.0 • Published 4 years ago

modify-xml v0.2.0

Weekly downloads
90
License
MIT
Repository
github
Last release
4 years ago

modify-xml

An easy way to modify XML documents without changing the formatting of the original. This module is part of the atscm project.

This module is still under development, do not use it in production yet

CircleCI

Installation

As usual, run npm i modify-xml.

Usage

import { promises } from 'fs';
import { parse, render } from 'modify-xml';

const xml = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<script>
  <metadata>
    <parameter name="stringParam" type="string" trigger="false" relative="false" value="Sample string" />
    <parameter name="numberParam" type="number" trigger="false" relative="false" value="0" />
  </metadata>
  <code><![CDATA[/*
 * Yes, it supports cdata
 */]]></code>
</script>`;

// Parse the XML string
const document = parse(xml);

// Process the resulting document

// Render the document back to XML using two spaces as indent
const result = render(document, { indent: '  ' });