⚡ Curated dev resources & dealsSponsored
DevToolBayFree Developer Tools

XML Formatter

Pretty-print messy XML with proper indentation, or minify it to a single line. Attributes, comments and text nodes are handled safely, with parse errors explained.

Mode
Indent

Notes

Formatting uses the browser's native DOMParser, so CDATA, comments, processing instructions and namespaces are recognised. Attribute order is preserved; text-only elements stay on one line (<item>text</item>). When parsing fails you'll see why — unclosed or mismatched tags are reported.

How to use XML Formatter

Paste XML and pick an indent width — the formatter re-prints the document with consistent indentation while preserving CDATA sections, processing instructions, comments and namespace declarations byte-for-byte. Minify mode strips inter-element whitespace and reports the size change.

Malformed input is rejected with the exact position — the mismatched-bracket report points at the line where the parser gave up, not where the mistake started. Use the formatter to review machine-generated XML (pom.xml, sitemap entries, SOAP payloads) after each regeneration round.

Frequently asked questions

Does the formatter support XML namespaces?

Yes. Namespaces, prefixes and attributes parse faithfully — formatting only touches indentation and whitespace between tags, never element content or attribute values.

How are comments and CDATA sections handled?

Comments and CDATA are preserved exactly in format mode and can be stripped in minify mode, matching what typical build pipelines expect.

Can the tool fix malformed XML?

It does not repair content, but it pinpoints the failing tag with line and column — a missing close tag or an unescaped ampersand is located immediately.

Does minified XML stay valid?

Yes. Minification merges inter-tag whitespace only. Text nodes that could change meaning are detected and left untouched, so documents remain interchangeable with the original.

Related tools