JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3237
  • Score
    100M100P100Q121619F
  • License MIT

XML pretty formatter that corresponds to the self-closing empty elements.

Package Exports

  • xml-beautify

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (xml-beautify) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Overview

xml-beautify - pretty-print text in XML formats.

It is licensed under MIT license.

How to use?

var beautifiedXmlText = new XmlBeautify().beautify(srcXmlText, 
    {
        indent: "  ",  //indent pattern like white spaces
        useSelfClosingElement: true //true:use self-closing element when empty element.
    });

Demo

demo on the web

https://riversun.github.io/xml-beautify/index.html

download standalone *.js

https://github.com/riversun/xml-beautify/blob/master/dist/XmlBeautify.js


demo on node.js

clone this project and type

git clone https://github.com/riversun/xml-beautify.git
npm start

install via npm

npm install xml-beautify

Example

[BEFORE] source XML

<?xml version="1.0" encoding="utf-8"?><example version="2.0">
  <head>
    <title>Original Title</title>
  </head>
  <body>
    <element message="Greeting" title="Chapter1">
      <element message="We say good morning in the morning."></element><element message="We say hello at noon."/>
      <element message="We say good evening at night."/>
    </element>
    <element message="Thank" title="Chapter2">
      <element>value</element>
      <element></element>
    </element>
  </body>
</example>

[AFTER] beautified XML

<?xml version="1.0" encoding="utf-8"?>
<example version="2.0">
  <head>
    <title>Original Title</title>
  </head>
  <body>
    <element message="Greeting" title="Chapter1">
      <element message="We say good morning in the morning." />
      <element message="We say hello at noon." />
      <element message="We say good evening at night." />
    </element>
    <element message="Thank" title="Chapter2">
      <element>value</element>
      <element />
    </element>
  </body>
</example>