XML Formatter
Beautify, minify, and validate XML documents with custom indentation. Preserves CDATA sections, comments, and processing instructions. Everything runs in your browser — no upload, no tracking.
About this tool
The XML Formatter is a fully client-side tool for working with XML documents. It pretty-prints messy single-line XML with consistent indentation, compresses verbose XML for transmission, and validates structure to catch common syntax errors before you ship config files or API payloads.
What it handles
- XML declaration —
<?xml version="1.0" encoding="UTF-8"?>recognized and placed on its own line - DOCTYPE — preserved as-is, with internal subsets supported
- Processing instructions —
<?xml-stylesheet ?>and similar PIs - CDATA sections —
<![CDATA[...]]>content preserved verbatim, never reformatted - Comments —
<!-- ... -->kept exactly as written - Self-closing elements — optionally collapsed from
<tag></tag>to<tag/> - Namespaces —
xmlns:prefixattributes treated like any other attribute - Mixed content — text alongside elements is handled without breaking inline structure
Beautify vs. Minify
Beautify rebuilds the document with each element on its own line at the correct indentation depth. Attributes stay on the opening tag. Text nodes are optionally trimmed of leading/trailing whitespace. The result is human-readable XML suitable for editing or code review.
Minify collapses whitespace between elements and normalizes attribute spacing to a single space. Content inside CDATA and comments is left untouched — those regions are extracted before processing and restored afterward via placeholder tokens, so nothing inside them gets accidentally mangled.
Validation
The validator catches the most common authoring mistakes: unclosed tags, mismatched closing tags, unquoted attribute values, unbalanced CDATA or comment delimiters, and malformed declarations. Errors are reported with the line number where they were detected, so you can jump straight to the problem in your editor.
Privacy
Everything runs in JavaScript inside your browser. No XML is uploaded, logged, or transmitted to any server. This makes the tool safe for sensitive content like API responses with private data, internal configuration files, or proprietary schema definitions.
FAQ
What is an XML formatter?
An XML formatter is a tool that transforms XML documents into a more readable form by adding consistent indentation and line breaks (beautify), or compresses them by removing unnecessary whitespace (minify). It also validates XML syntax to catch malformed tags or attributes.
Does this tool preserve CDATA sections and comments?
Yes. Content inside CDATA sections and XML comments is preserved verbatim during both beautify and minify operations. Whitespace is only collapsed in element-to-element gaps and inside tag attributes, never inside CDATA or comments.
Can it validate my XML?
Yes. The Validate button checks for matching tags, properly quoted attributes, balanced CDATA and comment delimiters, and well-formed declarations. Errors are reported with line numbers so you can locate problems quickly.
Is my XML data uploaded to a server?
No. All processing happens in your browser using JavaScript. Your XML never leaves your device, making this tool safe for sensitive configuration files, API payloads, or proprietary data.
What indent options are supported?
You can choose 2 spaces, 4 spaces, or tab characters for indentation. Line endings can be set to LF (Unix) or CRLF (Windows) depending on your target environment.
Does it handle namespaces and processing instructions?
Yes. XML namespaces (xmlns attributes) are preserved as regular attributes. Processing instructions like <?xml-stylesheet ?> and the XML declaration <?xml version="1.0"?> are recognized and formatted on their own lines.