Skip to main content

XML Beautify/Minify

Format, minify, and validate XML documents. Beautify adds indentation; minify collapses whitespace; validation checks well-formedness.

Overview

The XML Beautify/Minify tool provides:
  • Beautify — Indents tags with 2 spaces using xml-formatter
  • Minify — Removes whitespace between tags
  • Validation — Parses XML with fast-xml-parser to detect errors
Supports XML namespaces, CDATA, processing instructions, and attributes.

Use Cases

XML cleanup

Format XML from APIs, databases, or legacy systems for readability

File size reduction

Minify XML configuration files or SOAP messages

Validation

Check XML well-formedness before processing or transmission

Debugging

Beautify minified XML from third-party services

Actions

Uses the xml-formatter library to indent tags with 2 spaces. Preserves CDATA, comments, and attributes.Input:
<root><item id="1"><name>Product</name></item></root>
Output:
<root>
  <item id="1">
    <name>Product</name>
  </item>
</root>

Validation

The tool validates XML before beautification or minification using fast-xml-parser. If the XML is malformed, an error is returned.
Input:
<root>
  <item>Unclosed tag
</root>
Output:
Unclosed tag at line 2

Implementation Details

The tool imports fast-xml-parser for validation and xml-formatter for beautification. Source: lib/tools/engine.ts:544-549
Key logic
case 'xml-beautify': {
  const { XMLParser } = await import('fast-xml-parser');
  const parser = new XMLParser();
  parser.parse(input);  // Throws if invalid
  return { output: action === 'minify' ? input.replace(/>\s+</g, '><').trim() : (await import('xml-formatter')).default(input, { indentation: '  ' }) };
}
The minify operation is a simple regex (/>\s+</g) and does not preserve whitespace-sensitive content inside text nodes or CDATA.

XML Feature Support

<root xmlns:ns="http://example.com">
  <ns:item>Content</ns:item>
</root>
Namespaces are preserved during beautification and minification.
<script><![CDATA[
  function test() { return true; }
]]></script>
CDATA sections are preserved. xml-formatter does not modify CDATA content.
<?xml version="1.0" encoding="UTF-8"?>
<root/>
Processing instructions (e.g., <?xml ... ?>) are preserved.
<!-- This is a comment -->
<root/>
Comments are preserved during beautification and removed during minification.
The tool validates well-formedness only. It does not validate against DTD, XSD, or RelaxNG schemas.

Keyboard Shortcuts

  • Cmd/Ctrl+Enter — Beautify (default)
  • Cmd/Ctrl+Shift+C — Copy output
  • Cmd/Ctrl+Shift+S — Download output

HTML Beautify/Minify

Format or minify HTML markup

JSON Format/Validate

Validate and format JSON

YAML to JSON

Convert YAML to JSON