9314JIUsi
Developer tools · XML

XML formatter & validator: one-line mess to indent tree

2/4-space beautify, one-line minify; errors with line:column coordinates; CDATA, namespaces and comments preserved, round-trip stable.

TYPE CASE Own parser · DOMParser cross-check · 1MB cap
Indent
Mode
XML input
Output (live)

XML content is processed inside this device's browser only - nothing is uploaded, nothing is collected, and it works offline; indent and mode preferences live in this browser's localStorage and are lost if you switch devices or clear site data. To remove them, use "Clear my data" in the footer.

Three steps, done

  1. PasteDrop the one-line XML into the left, or hit "Load sample" for a full demo with CDATA, comments and namespaces.
  2. PickIndent 2 or 4 spaces, format or minify; the right side refreshes live, errors give line:column coordinates.
  3. Round-tripHit "Output → input" and process again - the two outputs should match character for character.

Parameters and boundaries

InputWell-formed XML 1.0 (elements/attributes/comments/CDATA/XML declaration/processing instructions); up to 1MB per run
OutputFormatted (2/4-space indent, attributes verbatim, comments and CDATA preserved) or minified (one line, indent/newlines stripped); errors with line:column coordinates
Key parameters2-space indent by default; ?indent=4&mode=minify deep-links directly; whitespace inside text nodes is preserved as content
ProcessingBrowser-local own parser (DOMParser used only as a cross-check) - no uploads, no accounts; preferences in localStorage (nothing written on first load)
Limits1MB per run (rejected with a message beyond that); nesting depth capped at 200 (stack-overflow guard)
Known limitsNo DTD validation, no XSD/Schema validation, no external entity resolution (XXE surface closed shut); no XPath queries; HTML entities (  etc.) are reported as undefined - that is HTML, not XML

FAQ

How do I use the line:column coordinates in an error?

Just count along: lines start at 1 counted by newline characters, columns start at 1 counted by characters, pointing at the offending character. For example "3:15 attribute value missing quotes" means around column 15 of line 3 there is an unquoted attribute value. It is the same convention as our JSON tool's errors - fix it, press the button again, and it passes. The browser's native DOMParser only hands you a single parsererror word with no coordinates, which is exactly why this page uses its own parser.

Will my comments and CDATA survive?

Yes. Comments are preserved verbatim in formatted output (indented to their nesting level), and CDATA sections pass through untouched - the < and & inside them are never modified. Self-closing tags keep their self-closing form instead of being expanded into an open/close pair. Namespace prefixes (ns:tag, xmlns:ns=...) are treated as part of the plain name, so prefixes never get stripped.

Does format → minify → format drift the output?

No - the round trip is stable: format, minify, format again, and the second output matches the first character for character. The reason is that minification only strips the indentation and newlines that formatting introduced; it never touches tag internals or text content. Whitespace inside text nodes belongs to the content and is preserved as-is. Run three rounds on any input and see for yourself.

Can this work as an XML validator? How is it different from DOMParser?

Yes. The common errors are all covered: unclosed tags, mismatched close tags, unquoted attribute values, bare ampersands, undefined entities (&nbsp; and friends are HTML, illegal in XML), illegal name start characters, and misplaced XML declarations. The difference is error quality: DOMParser returns one parsererror string with no coordinates, this page gives line:column. The page also runs DOMParser as a cross-check in parallel - both must pass before output is produced.

Is my config file uploaded anywhere?

No. Formatting, minification and validation all happen inside this device's browser - there is no upload endpoint and it works offline. Only preferences like indent width live in this browser's localStorage; they do not follow you to another device, and "Clear my data" in the footer removes them.

Related tools