ToolHub

XML Formatter

Format or minify XML

Invalid XML

Invalid XML

Beautify re-indents messy or minified XML with clean 2-space nesting so it is easy to read. Minify strips the whitespace between tags to shrink the payload. Input is validated as you type. Everything runs in your browser.

Overview

Format and minify XML in your browser

XML (Extensible Markup Language) stores structured data in nested tags. It is everywhere: RSS and Atom feeds, SVG graphics, SOAP web services, Android layouts, Office documents, sitemaps, and countless configuration files. The problem is that real-world XML is often a single unreadable line, or it is so deeply indented that you cannot tell where one element ends and the next begins.

ToolHub XML Formatter fixes both directions. Beautify re-indents your markup with clean 2-space nesting so the structure is obvious. Minify strips the whitespace between tags to produce the smallest valid payload. Your input is validated as you type, so malformed markup is caught immediately. Everything happens in your browser.

Step-by-step

How to format or minify XML

  1. 1

    Choose Beautify or Minify

    Beautify pretty-prints your XML with indentation. Minify removes the insignificant whitespace between tags.
  2. 2

    Paste your XML

    Drop your markup into the input panel. The output updates live as you type or switch modes.
  3. 3

    Check validity

    A badge tells you whether the XML is well-formed. If it is not, an inline message points you at the problem.
  4. 4

    Copy the result

    Click copy to grab the formatted or minified XML for your editor, feed, or API request.

Background

What well-formed XML means

XML has strict rules. Every opening tag like <item> needs a matching closing tag </item> or must be self-closing like <item/>. Tags must nest properly, attribute values must be quoted, and there can be only one root element. When all of these hold, the document is well-formed and a parser can read it.

How validation works here

This tool runs your input through the browser built-in DOMParser. If the parser reports an error, the markup is not well-formed and we show you a clear message instead of producing broken output. Beautifying only happens once the XML parses cleanly.

Beautify versus minify

Beautify adds newlines and indentation so a human can scan the hierarchy. Minify does the opposite, collapsing whitespace between tags to save bytes for transport. Both produce the same data, just formatted for different audiences: people versus machines.

Whitespace and text content

The formatter keeps short text values on the same line as their tags, so <to>Tove</to> stays compact rather than exploding onto three lines. It only collapses the whitespace that sits between tags, which is insignificant to the data.

Use cases

When to use an XML formatter

Debugging API responses

SOAP and legacy REST services return XML on one line. Beautify it to read the structure while debugging.

Editing RSS and Atom feeds

Hand-edit feed items with confidence by formatting the markup so nesting and tags are clear.

Cleaning SVG markup

Pretty-print exported SVG to inspect paths and attributes, or minify it before shipping.

Shrinking config and sitemap files

Minify XML sitemaps and configuration to reduce file size for faster delivery.

Reviewing Android or XAML layouts

Re-indent UI layout files that got mangled by a merge so the view tree reads cleanly.

Validating before deploy

Catch unclosed tags and mismatched nesting before the markup reaches a strict parser in production.

Tips and best practices

  • Minify XML for transport, but keep a beautified copy in version control so diffs stay readable.
  • If validation fails, look for an unclosed tag or an unquoted attribute first. Those are the most common causes.
  • XML allows only one root element. Wrapping fragments in a single parent tag fixes many parse errors.
  • Whitespace inside text content can be significant. Minifying collapses it, so check that your data does not rely on exact spacing.
  • For very large documents, beautified output can be many times larger than minified. Use the mode that fits the task.

Common questions

Does formatting change my data?

No. Beautify and minify only add or remove the insignificant whitespace between tags. The elements, attributes, and text values are untouched, so the parsed result is identical.

Why does my XML show as invalid?

The browser parser found a problem: an unclosed tag, mismatched nesting, an unquoted attribute, or more than one root element. Fix the flagged issue and the badge turns green. HTML is not always valid XML, so HTML-only constructs can trigger errors too.

Can it handle XML declarations and comments?

Yes. The processing instruction at the top like <?xml version="1.0"?> and comments like <!-- note --> are preserved on their own lines when beautifying.

Is there a size limit?

Only your device. Because everything runs locally in the browser, there is no upload cap from a server. Extremely large files may simply be slower to render in the text area.

100% private

Privacy and security

Your XML is parsed and formatted entirely in your browser using the built-in DOMParser. Nothing you paste or upload is sent to a server, logged, or stored.

Related tools

Frequently asked questions

Can it both format and minify?

Yes. Switch between Beautify for clean indentation and Minify to remove whitespace and shrink the file.

Does it validate the XML?

Yes. Malformed XML is detected and an error is shown so you can fix it.

Is my XML private?

Yes. Formatting happens in your browser and nothing is uploaded.