ToolJutsu
All tools
Developer Tools

XML Formatter

Pretty-print and indent messy XML.

0 chars
Tip: press Ctrl/ + Enter
Processed on your device. We never see your files.

How to use XML Formatter

What this tool does

This tool cleans up XML. Format mode re-indents a document so its structure is easy to read — useful when XML arrives as one long line or with inconsistent spacing. Minify mode does the reverse, stripping the insignificant whitespace between tags to produce the smallest valid output. Both modes start by parsing the XML with the browser’s native DOMParser, so malformed input is caught before anything is produced. Everything runs on your device; the XML you paste is never uploaded.

Why you might need it

XML configuration files, SOAP responses, RSS feeds, sitemaps, and build descriptors are often generated by machines and shipped without any formatting — a single unreadable line, or indentation that does not match the nesting. To review a diff, debug a response, or simply understand the structure, you need it laid out cleanly. Minification solves the opposite problem: when XML is sent over a network or embedded in another document, the whitespace is wasted bytes.

How to use it

  1. Paste your XML into the input box, or drop an .xml file onto it.
  2. Choose Format to pretty-print, or Minify to compact.
  3. For Format, pick an indentation width: 2 spaces, 4 spaces, or tab.
  4. Click the action button, or press Ctrl/Cmd + Enter.
  5. Copy the result with one click. The character counter shows how much minifying saved.

How it works

Rather than reformatting the raw text with string tricks, the tool parses the XML into a real document tree and then walks that tree to produce output. This means the result is always well-formed: tags are balanced, attributes are escaped, and nesting is correct. When formatting, an element whose only content is text — like <title>Hello</title> — is kept on a single line, while elements with child elements are expanded with each child on its own indented line. Empty elements collapse to the self-closing form <tag/>. Minifying joins everything back together with no whitespace between tags, while still preserving meaningful text content.

Common pitfalls

The most important thing to know is that whitespace inside an element can be significant in XML, and a formatter cannot always tell. When an element contains only text, this tool trims and normalises that text — which is the right choice almost always, but if you rely on exact leading or trailing spaces inside a text-only element, formatting will change them. Mixed content (text interleaved with child elements) has its text segments placed on their own lines, which can shift meaning in rare document-style XML. If your input fails to parse, look for unclosed or mismatched tags, or unescaped < and & characters in text — those are the usual causes of a malformed document.

Tips and advanced use

Use Minify before sending XML across a network or storing it, then Format again whenever you need to inspect it — the two are reversible in terms of meaning. When comparing two XML files in a diff tool, format both with the same indentation first so the comparison lines up cleanly. The XML declaration and any comments survive both modes, so formatted output stays a complete, valid document. And because all parsing and serialising happens in your browser, you can tidy up XML that contains internal endpoints or credentials without any of it leaving your machine.

Frequently asked questions

Is my XML sent to a server?
No. The XML is parsed and re-formatted entirely in your browser using the built-in DOMParser. Nothing you paste or drop is uploaded, so it is safe for sensitive configuration files. You can confirm this in the browser's Network tab.
What is the difference between Format and Minify?
Format pretty-prints XML with line breaks and indentation so it is easy for people to read. Minify removes the insignificant whitespace between tags to make the document as small as possible for transmission or storage.
Will formatting change the meaning of my XML?
No. Formatting only adjusts whitespace between elements. Element names, attributes, attribute order within each element, and text content are all preserved. Whitespace inside text content is normalised when an element holds only text.
What happens if my XML is malformed?
The browser's parser flags malformed XML by producing a parsererror element. The tool detects this and shows a clear error message, usually naming the line where parsing failed, rather than emitting broken output.
Does it keep comments and CDATA sections?
Yes. Comments are preserved on their own lines when formatting, and CDATA text content is kept. The XML declaration at the start of the document is also retained if your input had one.

Related tools