← All tools

XML Formatter

Beautify or minify XML documents locally — private and instant.

Free tool No account
Input
Output

✓ Well-formed XML

AI uses your own key (several are free); a button opens a short setup.
Ready267 in · 316 outProcessed locally · No upload
Enjoying XML Formatter?Your review and ideas shape what we build next.

Review XML Formatter

Please don't include file contents or passwords.

About the XML Formatter

Paste XML to lay it out with clear indentation, or minify it to one line. The formatter also checks that the XML is well-formed and tells you the line of any tag that isn't closed or doesn't match. CDATA sections, comments, processing instructions and attributes are kept exactly as they are.

How to use it

  1. Paste the XML into the Input box (or press Sample).
  2. Choose Beautify with 2, 4 or 8 spaces or a tab, or Minify. When minifying you can also remove comments.
  3. Read the status line: “Well-formed XML”, or the line and the tag that's wrong.
  4. Copy or download the result.

Tip: If the status line says a tag doesn't match, look at the line it names and the line where that tag was opened: a missing </tag> in between is the usual cause.

Well-formed XML in five rules

Well-formed means the XML follows the basic grammar, which is what every XML parser needs before it can read the file.

One root element
Everything sits inside a single outer element, such as <catalog>…</catalog>.
Every tag is closed
Either <item>…</item> or the self-closing form <item/>.
Tags close in order
<a><b></b></a> is right; <a><b></a></b> is not.
Attribute values in quotes
<book id="b1">, with single or double quotes.
Special characters escaped
Write &lt; for <, &amp; for & in text, or put the text in a CDATA section.

Beautify vs minify

Beautify
Each element on its own line, nested by depth; short elements such as <title>Clean Code</title> stay on one line so the file stays easy to scan.
Minify
Removes only the whitespace between tags. Text inside elements, attribute values, CDATA and comments are not touched, so the meaning of the document can't change.
Remove comments
Optional when minifying, for the smallest file to send.

CDATA, comments and declarations

A CDATA section (<![CDATA[ … ]]>) holds text that may contain < and & without escaping: scripts, HTML snippets or code samples. The formatter never re-spaces or changes what's inside it.

Comments (<!-- … -->), the XML declaration (<?xml version="1.0"?>) and a DOCTYPE are kept in place, each on its own line when beautifying.

Where you'll meet XML

Sitemaps and RSS feeds, Android layouts, Maven pom.xml files, SOAP web services, SVG pictures, Office files (inside DOCX and XLSX), and e-invoices such as UBL and Factur-X are all XML. Formatting them makes a problem far easier to spot.

Escaping special characters

Five characters have a special meaning in XML. Inside text and attribute values, write them like this:

< (less than)
&lt;
> (greater than)
&gt; (needed in a few places, safe everywhere)
& (ampersand)
&amp;: the most common cause of broken XML, for example in URLs with ?a=1&b=2
" (double quote)
&quot; inside an attribute written with double quotes
' (apostrophe)
&apos; inside an attribute written with single quotes

Elements, attributes and namespaces

Data can go in an element (<price>29.99</price>) or an attribute (<price currency="USD">). Attributes suit short facts about an element; elements suit content and anything that repeats or nests.

Namespaces such as xmlns:g="http://base.google.com/ns/1.0" let one file mix vocabularies (Google Shopping feeds, SOAP, SVG inside HTML). The formatter keeps prefixes like <g:price> exactly as written.

The XML declaration and character encoding

The first line of many files, <?xml version="1.0" encoding="UTF-8"?>, tells a parser which XML version and which character encoding the file uses. It's optional for UTF-8 files, but if it's there it must be the very first thing, with nothing before it, not even a space or an empty line.

If accented letters or Arabic and Urdu text look broken after opening a file elsewhere, the encoding in the declaration probably doesn't match how the file was saved. Saving as UTF-8 and declaring UTF-8 is the safe choice for almost every file today.

Tips and tricks

Debug a sitemap

Paste your sitemap.xml to check it's well-formed before submitting it to Google Search Console.

Read a SOAP response

Beautify a one-line SOAP reply to see the fault message at a glance.

Check an SVG

SVG is XML; a broken SVG usually has an unclosed tag the checker will find.

Spot the missing tag

The error names both the closing tag and the line where the open tag started.

Use tabs for big files

Tab indentation keeps deeply nested files narrower in most editors.

Keep secrets local

Nothing is uploaded, so configuration files with passwords stay on your device.

Questions

Does it check that my XML is valid?

It checks that the XML is well-formed: one root, every tag closed and in the right order, comments and CDATA closed. It doesn't check against a schema (XSD or DTD).

Will minifying change my data?

No. Only whitespace between tags is removed; text, attributes, CDATA and comments stay exactly as they were.

Can I remove XML comments?

Yes. Choose Minify and tick remove comments.

What's the difference between XML and HTML?

HTML is a fixed set of tags for web pages and browsers forgive mistakes; XML lets you invent tags and must be well-formed. For HTML use the HTML Formatter.

Can I format an RSS feed or sitemap?

Yes, both are XML.

Does it work with namespaces?

Yes. Prefixed tags such as <soap:Envelope> or <g:price> are formatted and checked like any other tag, and kept exactly as written.

Can it convert XML to JSON?

Not this tool: it formats and checks XML. To work with the data as JSON, many APIs offer a JSON version of the same response.

Why does my file say the XML declaration is in the wrong place?

Something comes before <?xml …?>: usually a blank line, a space or an invisible byte-order mark. Delete everything before it so the declaration starts the file.

Is my data uploaded?

No. The tool runs in your browser; what you paste or open never leaves your device and nothing is stored on a server.

Related tools

Updated