Home » Developer Tools » XML Beautifier

XML Beautifier

Turn messy single line XML into clean, readable, indented code.

Last updated 13 November 2026

Upload a file: or paste code below.
Input0 chars
Output0 chars
Original size0 B
Result size0 B
Change0%

Your code never leaves your browser. Everything runs locally on your device.

This tool only formats code. It does not run, compile or execute it, so always review the formatted output before you use it in a project.

XML that arrives on one long line is hard to read, hard to debug, and easy to break when you edit it by hand. The BotixTech XML Beautifier rebuilds it with clean indentation, so every nested element sits exactly where you expect it.

Paste your XML or upload a file, pick an indent size, and get readable output with elements on their own lines, mixed content kept inline, and CDATA and comments placed clearly. Everything runs in your browser, so your data stays private.

How to Beautify XML

  1. Paste or upload your XML. Type or paste code into the input box, or upload an XML file from your device.
  2. Pick an indent size. Choose 2 spaces or 4 spaces, and decide whether comments stay in the formatted output.
  3. Watch the result appear as you type. The formatted result shows up as you type, with clean nesting and readable structure. Click Beautify XML any time to run it again by hand.
  4. Copy or download it. Copy the beautified XML to your clipboard or download it as a file for your project.

Why Use This XML Beautifier

What Is an XML Beautifier

An XML beautifier is a tool that takes compact XML and rewrites it with clean spacing and indentation. Each nested element moves one level deeper, each closing tag lines up with its opening tag, and a document that arrived as one long line becomes a page you can read at a glance. Beautifier, formatter and pretty printer are three names for the same job, and this page uses all three because people search for all three.

The tool only changes how the code looks. It does not change what the code means, it does not add or remove elements, and it does not check your XML against a schema. Your document comes out with the same elements, the same attributes and the same values, only laid out so a person can follow it.

Two small details are worth knowing, and the FAQ below states them plainly. Whitespace inside text values can be tidied up, and character references are expanded to the characters they stand for. The structure and the data stay the same, but text that relies on exact spacing should be checked after formatting.

Worked Example

Here is a small document run through the tool, with the exact numbers:

Input, 63 characters:

<root><item id="1">Hello</item><item id="2">World</item></root>

Output with 2 space indent, 70 characters:

<root>
  <item id="1">Hello</item>
  <item id="2">World</item>
</root>

The output is 70 characters, up from 63. That is 7 characters added, and 7 divided by 63 is 0.1111, so the file is about 11 percent larger. The structure is now plain to see: the root element opens the document, the two item elements sit one level deeper, and the closing tag lines up with the opening tag.

The Load Sample button shows the same effect on a bigger file. Its 290 character sample, a small library with two books, formats to 351 characters, about 21 percent larger. The sample has mixed content, a CDATA block, a comment and an empty element, so it shows every feature of the formatter at once.

Well Formed vs Valid XML

Formatting checks that your XML is well formed, which means every opening tag has a matching closing tag, tags nest in the right order, attribute values sit inside quotes, and there is exactly one root element. If any of those rules break, the tool shows a friendly invalid XML message and leaves your input untouched, so you can fix the error and try again.

Well formed is not the same as valid. A valid document also follows a schema, which is a separate file that says which elements and attributes are allowed and in what order. This tool does not check your XML against a schema, so a file can format cleanly here and still fail a schema check in another tool. If you need schema validation, check the file against its XSD or DTD after you format it.

One more limit is worth stating plainly. The error message names the problem but not the line or column where it sits, so for a long file you may need to search for the fault by hand. Tab indent is also not offered yet: indent is 2 spaces or 4 spaces only.

What You Can Format With It

Any well formed XML file works here. Sitemaps are a common case: a sitemap is one long list of URL entries, and formatting it turns a wall of text into a list you can scan and check. RSS and Atom feeds are the same shape, a list of items with titles, links and dates, and they become far easier to read once each item sits on its own lines.

Config files are another everyday case. Android layout files, Maven pom.xml files and .NET config files are all XML, and they all arrive minified or cramped when they come out of a build tool or a download. Paste the file here, format it, and you can see the structure before you change a value.

The same goes for SOAP envelopes, the XML messages that older web services send back and forth, and for SVG images, which are XML documents that draw shapes. A formatted SVG shows each shape on its own lines, so you can find the path or group you need without hunting through one long line.

Beautifier vs Minifier

A beautifier and a minifier do opposite jobs. A beautifier makes XML bigger and easier to read by adding spaces, line breaks and indentation. A minifier makes XML smaller and harder to read by removing those same things. You beautify when you need to read or fix a file, and you minify when you need to publish it or send it over a network.

Use the XML Minifier when your document is ready to go live. It strips the extra whitespace so the file downloads faster and takes up less space. Keep your readable copy for editing, publish the minified copy, and come back here whenever you need to read it again.

Common XML Errors and How to Fix Them

Most XML errors come from a short list of small mistakes. A bare ampersand is the most common: a plain & in text must be written as &amp; in XML, so a company name like Smith & Sons breaks the parse until you write Smith &amp; Sons. The same rule applies to the less than sign, which must be written as &lt; when it appears in text.

Unquoted attribute values are next. An attribute like id=bk201 needs quotes around the value, so write id="bk201". The parser rejects the unquoted form every time.

Mismatched tags are the third common fault: an opening <book> closed by </books> fails, and so does a tag closed in the wrong order. Read the nesting from the inside out and close the most recent tag first.

The last common fault is a declaration in the wrong place. The line <?xml version="1.0"?> must sit at the very start of the file, before any space or comment. A blank line or a stray character before it is an error.

How to Format XML Somewhere Else

If you format XML every day, your editor may already do it. In Notepad++, install the XML Tools plugin, then use the Pretty Print command on the Plugins menu. In VS Code, install the XML extension by Red Hat, then use Format Document from the Command Palette. Both tools reindent the file in place, so you never leave your editor.

On the command line, xmllint does the same job with one command:

xmllint --format input.xml

Add > output.xml to the end of that command to write the result to a file instead of the screen.

In Python, the standard library can indent a parsed tree:

import xml.etree.ElementTree as ET
tree = ET.parse("input.xml")
ET.indent(tree, space="  ")
tree.write("output.xml")

ET.indent needs Python 3.9 or newer. Older versions need a small helper instead, which is one more reason to format the file here when you only need a quick result.

Frequently Asked Questions

Does the XML beautifier change my data?

No. It only changes whitespace and layout. Element names, attributes and CDATA content stay the same, and the structure of your document is untouched. Two small details are worth knowing. Whitespace inside text values can be tidied up, so runs of spaces collapse to one space and extra space at the start or end of a text value is trimmed. Character references are also expanded, so a code like © becomes the literal character in the output. The tool does not honour xml:space preserve, so text that relies on exact spacing should be checked after formatting.

How does it handle text mixed with tags?

Text that sits next to inline tags stays on one line, so sentences and mixed content read naturally instead of being split across lines.

What happens to empty elements?

Empty elements are written as self closing tags, which keeps the output short and easy to scan.

Are CDATA sections and comments kept?

Yes. CDATA sections keep their exact content on their own lines, and comments stay on their own lines unless you turn the keep comments option off.

What happens if my XML has an error?

The tool shows a friendly invalid XML message and leaves your input untouched, so you can fix the error before trying again.

Can I choose the indent size?

Yes. You can format with 2 spaces or 4 spaces, depending on the style your project uses.

Is an XML beautifier the same as an XML formatter?

Yes. Beautifier, formatter and pretty printer are three names for the same job: turning compact XML into clean indented markup. This page uses all three names because people search for all three, but the tool behind them is the same.

Can I format a sitemap, RSS feed or SVG file?

Yes. Any well formed XML file works, including sitemaps, RSS and Atom feeds, SOAP envelopes, SVG images, Android layout files, Maven pom.xml files and .NET config files. If the file is well formed, the tool formats it. If it has an error, the tool shows a message and leaves your input untouched.

Does formatting make my XML valid?

No. Formatting only changes layout, it does not check your XML against a schema. The tool checks that your XML is well formed, which means tags are closed and nested correctly. It does not check that it is valid against an XSD or DTD, so a file can format cleanly here and still fail a schema check elsewhere.

Is there a file size limit?

The page does not state a file size limit. Your XML is formatted in your browser, so a very large file may take a moment to process. If you work with a huge file, paste a section first to check the result before you format the whole document.

↑