XML Formatter
Interactive StudioFormat and validate XML with proper indentation, using your browser's native XML parser. Instant feedback with zero server storage.
Loading tool…
About XML Formatter
XML represents data as nested elements with attributes and text content, and this formatter re-indents that nesting so the document's structure is visible at a glance. It uses the browser's built-in DOMParser to actually parse the document into a DOM tree — rather than just inserting line breaks with regex — then walks that tree recursively, printing self-closing tags for empty elements, single-line tags for elements containing only text, and nested indented blocks for elements with element children.
Because parsing goes through DOMParser, the formatter also validates well-formedness as a side effect: XML requires every tag to be properly closed and nested (unlike HTML, which tolerates some sloppiness), so a missing closing tag or mismatched nesting produces a clear parse error instead of a best-effort guess at formatting. Text nodes that are pure whitespace between elements are trimmed away, so indentation is rebuilt cleanly rather than preserved from the original formatting.
This is useful for reading a minified XML API response, a config file, or an RSS/Atom feed that arrived as one dense line, and for catching structural mistakes like an unclosed tag before they cause problems downstream.
How to use XML Formatter
- Paste your XML.
- The document is parsed and rewritten with consistent indentation.
- Copy the result. Invalid XML shows an error instead.
Worked examples
Input: <a><b>1</b><c/></a>
Result: <a> on line 1, <b>1</b> and <c/> each on an indented line, then </a>.
Background
XML must be well-formed: one root element, properly nested tags, matching case, quoted attributes and escaped special characters (& < >). The tool uses the browser's DOMParser, so malformed documents are rejected rather than guessed at.
Whitespace can be meaningful in XML. Re-indenting is safe for data documents, but it can alter mixed content such as text interleaved with tags, so review the output for markup-heavy documents.
Common mistakes
- Leaving a bare & in text. It must be written &.
- Mismatched tag case. XML is case-sensitive.
- Having more than one root element.
Frequently Asked Questions
Frequently Paired With
Fast, local-first developer micro-tools with zero tracking or latency.
SQL Formatter
Format and beautify SQL queries.
JSON Formatter
Format, validate, and minify JSON with TypeScript & Zod export.
YAML Formatter
Format and validate YAML.
Hash Generator
Generate SHA-1/256/384/512 hashes of text.
