xml-beautify is an XML pretty-printer for Node.js and browser, version 1.2.3, released under MIT license. It formats XML text with customizable indent and self-closing element options. Maintained by riversun, it provides a simple API and works in both environments. Unlike alternatives, it preserves CDATA sections and self-closing tags. The package requires an external DOMParser (e.g., xmldom) when used in Node.js. The latest version is stable with no recent updates.
npm install xml-beautifyNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to use xml-beautify in Node.js with xmldom DOMParser, including indent and self-closing options.
Install xmldom: npm install xmldom, then pass { parser: DOMParser } to constructor.Use default import: import XmlBeautify from 'xml-beautify' or const XmlBeautify = require('xml-beautify').Explicitly set useSelfClosingElement: false if you want expanded empty elements.
Use script src='https://cdn.jsdelivr.net/npm/xml-beautify@1.2.3/dist/XmlBeautify.js' and access via window.XmlBeautify.
Install xmldom: npm install xmldom, then require it and pass to constructor: new XmlBeautify({ parser: DOMParser }).Use correct import: const XmlBeautify = require('xml-beautify'); or import XmlBeautify from 'xml-beautify';Ensure script tag loads XmlBeautify.js before calling new XmlBeautify(), or add type='module' for ES modules.