XML Formatter

Paste messy or single-line XML and get it indented and readable โ€” or minified for transport. Invalid XML is caught and explained instead of silently mangled.

How to format XML

  1. Paste the XML โ€” an RSS feed, a sitemap, a SOAP response, an Android layout, a config file.
  2. Choose 2 spaces, 4 spaces or tabs.
  3. Press Format XML to indent it, or Minify to strip formatting whitespace back out.

It validates while it formats

The formatter parses your document with the browser's own XML parser before it prints anything. If a tag is unclosed, an attribute is missing a quote, or an entity is undefined, you get the parser's error message instead of plausible-looking but wrong output. That makes it a quick way to check whether a feed or a sitemap is actually well-formed XML โ€” the most common cause of a feed silently failing to update.

Whitespace in XML is not always safe to change

Unlike HTML, XML treats whitespace inside an element as content. Re-indenting a document changes text nodes that contain only whitespace, and for most documents that is exactly what you want. But if an element carries xml:space="preserve", or if the content is significant โ€” a code block, a signed payload โ€” the reformatted document is technically different from the original. Never reformat a digitally signed XML document: it will break the signature. Mixed content (text and tags in the same element) is left on one line for this reason.

Minifying for size

Minify removes whitespace between elements while leaving text content alone. For a large sitemap or an API payload the saving is real, and gzip compresses the result further. Formatting is for humans; minifying is for the wire.

Benefits

  • Validates with the browser XML parser first, so malformed documents are reported rather than mangled.
  • Indents with 2 spaces, 4 spaces or tabs, and minifies back down on demand.
  • Preserves CDATA sections, comments, processing instructions and mixed content.
  • Works offline once loaded and never uploads your document.

Limitations to know

  • It formats well-formed XML; it does not validate against a DTD, XSD or schema.
  • Reformatting changes whitespace, which invalidates an XML digital signature.
  • Elements carrying xml:space="preserve" are not given special treatment.

Common mistakes to avoid

  • Formatting a signed document and then wondering why signature verification fails.
  • Assuming a formatter can repair broken XML โ€” it can only tell you where the break is.
  • Pasting HTML instead of XML; unclosed tags such as <br> are valid HTML but invalid XML.

Alternatives

For JSON documents use the JSON Formatter, for config files use the YAML to JSON Converter, and to compress markup use the HTML Minifier.

Last updated: August 2026 ยท Reviewed by the AI Toolbox editorial team.

Frequently asked questions

Does it fix broken XML?

No. It reports the error and its location so you can fix it โ€” a formatter that guessed at your intent could quietly corrupt data.

Are CDATA sections and comments preserved?

Yes. Both are kept intact; only whitespace between elements is changed.

Will it break my XML signature?

Reformatting changes the byte content, which invalidates an XML digital signature. Never format a signed document you intend to keep valid.

Is my file uploaded?

No. Parsing and formatting happen entirely in your browser using the built-in DOMParser.

Related tools