XML Formatter
Format XML with clean indentation, check that it is well-formed and jump to the line of any error.
About the XML Formatter
What is an XML formatter?
An XML formatter is a tool that puts each XML element on its own line, indented under its parent.
An XML formatter reads the document by the rules of XML 1.0, the W3C standard, and writes it back with line breaks and indentation between the tags. A careful one leaves text, attribute values and CDATA sections exactly as they were. People also call it an XML beautifier, an XML prettifier or a pretty printer.
Our formatter also checks that the XML is well-formed as you type. When something is broken, the status line names the problem with its line and column, and Go to line jumps to it in the input. Minify mode does the reverse and removes the whitespace between tags.
What should you know before you format XML?
Formatting XML is safe as long as only the whitespace between tags changes.
- Text inside an element is data. XML 1.0 requires a parser to pass every character that is not markup through to the application, so
<name> Ada </name>holds two spaces on each side, and trimming them changes the value. - Mixed content is left as written. In
<p>Hello <b>world</b> again</p>the spaces around<b>belong to the sentence, so the formatter leaves that element exactly as written. - The xml:space attribute protects whitespace. An element marked
xml:space="preserve"keeps every space and line break inside it when you format or minify, as section 2.10 of the XML 1.0 specification intends. - CDATA sections are never re-indented. The text between
<![CDATA[and]]>keeps its spaces and line breaks in both modes. - Namespaced values stay intact. An element like
<m:Get xmlns:m="urn:x">1</m:Get>keeps the value 1 on its line. Four popular online XML formatters we tested in September 2026 turned that value into 1 followed by a line break and tabs.
How do you format XML?
Paste XML into the input box, and the formatted copy appears in the output box.
- Add the XML. Paste it, drop a file onto the input box, press Open file, or press Sample to try an example.
- Choose the layout. Pick 2 spaces, 4 spaces or tabs, and decide whether each attribute gets its own line.
- Read the status line. It shows the root element with a count of elements and attributes, or the first problem with its line and column.
- Fix any error. Press Go to line to jump to the problem in the input box.
- Copy or download the result. Switch to Minify first when you need the smallest file.
Example
This one-line XML order will be converted to a tree with 4-space indentation, the default setting:
<?xml version="1.0" encoding="UTF-8"?><order id="1042"><customer>Ada Park</customer><items><item sku="KB-01" qty="1">Mechanical keyboard</item><item sku="MS-07" qty="2">Wireless mouse</item></items><tracking xmlns="urn:example:ship">TRK-20931</tracking><note>Leave it at the <b>side</b> door.</note></order>
<?xml version="1.0" encoding="UTF-8"?>
<order id="1042">
<customer>Ada Park</customer>
<items>
<item sku="KB-01" qty="1">Mechanical keyboard</item>
<item sku="MS-07" qty="2">Wireless mouse</item>
</items>
<tracking xmlns="urn:example:ship">TRK-20931</tracking>
<note>Leave it at the <b>side</b> door.</note>
</order>
The <tracking> value stays on one line even though that element declares its own namespace. The note keeps its sentence exactly as typed, because it mixes text with a <b> tag. Switch to Minify and the formatter turns the tree back into the original single line.
What are the ways to format XML?
You can format XML online, in a code editor, or from the command line.
| Method | How to format | What to install | Error checking | Best for |
|---|---|---|---|---|
| CodeShack XML Formatter | Paste the XML or open the file | Nothing | Well-formedness, with line and column | Quick checks and one-off files |
| Notepad++ | Plugins, XML Tools, Pretty print | The XML Tools plugin | Syntax check, plus XSD and DTD validation | Windows users who already edit in Notepad++ |
| Visual Studio Code | Format Document, Shift+Alt+F on Windows | An XML extension, such as XML by Red Hat | Syntax errors, plus XSD and DTD validation | XML files inside a code project |
| xmllint | xmllint --format file.xml | libxml2 | Well-formedness, plus XSD with --schema | Scripts and servers |
| Python | ElementTree.indent() | Nothing, from Python 3.9 | The parser stops at the first error | Formatting inside a program |
Editors and command-line tools suit XML that lives in a project or a script, and they can validate it against a schema. An online XML formatter suits a quick look at one file on any computer, with nothing to install.
Common mistakes
These three XML mistakes stop a file from being well-formed.
- A bare ampersand. Text like
AT&Tgets the error "A bare & must be written as &", because&always starts a reference in XML, such as<or©. WriteAT&Tinstead. - HTML entities in XML.
and©are built into HTML but not into XML, so the checker reports "The entity is not defined". Use the number instead, or©. - Anything above the XML declaration. A blank line or a space before
<?xml version="1.0"?>breaks the file, because the declaration has to be the very first thing in it. Delete everything above it.
Common Use Cases
People format XML to read it, to find a bug in it, or to compare two versions.
- SOAP messages. Lay out a SOAP request or response to find the field you need, with every namespaced value left intact.
- Sitemaps and RSS feeds. Check a sitemap.xml file or a feed before you publish it, and catch a stray ampersand that breaks it.
- SVG images. Exported or minified SVG can arrive as one long line, so format it before you edit a path by hand.
- Config and build files. Android layouts, Maven pom.xml files and .NET config files are easier to fix once they are indented.
- cXML orders and invoices. Purchase orders sent between procurement systems nest several levels deep, and a clean layout shows each line item.
- Clean XML before a comparison. Format two versions the same way, then compare them in Text Compare, so only real changes show up.
To browse a large document as a collapsible tree, open it in the XML Viewer. To turn XML into JSON, use the XML to JSON Converter, and to put elements in order, the XML Sorter.
Frequently Asked Questions
How does an XML beautifier work?
An XML beautifier reads XML into a tree of elements, then prints it again with indentation. A careful one changes only the whitespace between tags, never the text, attribute values or CDATA sections.
How do you format XML in Notepad++?
Install the XML Tools plugin in Notepad++, then choose Plugins, XML Tools, Pretty print. The same plugin can also check the syntax and validate the file against an XSD or DTD.
What is the difference between well-formed and valid XML?
Well-formed XML follows the syntax rules of XML 1.0, such as having one root element. Valid XML is also well-formed and matches a schema such as an XSD or DTD, which an XML validator or linter checks.
Does formatting XML change the data?
Formatting XML should change only the whitespace between tags. Our formatter leaves text, attribute values, CDATA sections and elements that use xml:space to preserve whitespace exactly as they were.
How do you make an XML file readable?
Open the XML file in an XML formatter to get one element per line with clear indentation. For a collapsible tree instead of text, open the file in an XML viewer.
Is XML still used today?
Yes, XML is still in wide use. Sitemaps, RSS feeds, SVG images, SOAP web services, Android layouts and the files inside .docx and .xlsx documents are all XML.