How to use the XML formatter
- Paste your XML into the Input box, or edit the sample.
- Choose an Indent: 2 spaces, 4 spaces or a tab.
- To put attributes on separate lines, set Put attributes on their own lines when an element has more than to a number such as 2. Leave it at 0 to keep attributes on one line.
- Untick Keep comments to drop
<!-- … -->comments. - Read the Formatted XML or the error message, then copy or download
formatted.xml.
What it does and when to use it
XML arrives squashed onto a single line from APIs, SOAP services, RSS and sitemap files, Android layouts, Office documents and many config systems. The formatter turns it into an indented tree, so you can see which element sits inside which and spot missing or extra tags.
It doubles as a quick well-formedness checker. If the markup is broken, you get a message such as “Expected closing tag ‘b’ … instead of closing tag ‘a’” with a line and column, instead of a silently mangled result.
Once your XML is readable, the XML to JSON converter can turn it into JSON, and the XML minifier packs it back down for sending. For SQL inside the same project, use the SQL formatter.
How it works
First, the well-formedness check runs with the fast-xml-parser validator, loaded in your browser when needed. If it fails, you see its message and position. If it passes, the tool’s own XML tokenizer reads the elements, attributes, comments, CDATA sections and processing instructions and prints them with one level of indent per nesting level. An element that holds only text stays on one line, such as <b>1</b>. Mixed content and xml:space="preserve" blocks are copied exactly. Attribute values and quotes are not changed.
Worked examples
These outputs come from the formatter.
Nested elements. <a><b>1</b><c x="1"/></a> becomes:
<a>
<b>1</b>
<c x="1"/>
</a>
A broken document. <a><b>1</a> gives: “XML is not well-formed at line 1, column 8: Expected closing tag ‘b’ (opened in line 1, col 4) instead of closing tag ‘a’.”
Attributes on their own lines. With the attribute limit set to 2, <book id="7" lang="en" format="pdf"><title>Notes</title></book> has three attributes, so each goes on its own line:
<book
id="7"
lang="en"
format="pdf">
<title>Notes</title>
</book>
Limits and tips
- The first error only. Fix it and paste again; later errors appear one at a time.
- Namespaces are kept as written, but prefixes are not checked against their declarations.
- Very large files (many megabytes) may make the page slow, because everything runs on your device.
- Keep a copy of the original if exact whitespace matters, for example in signed XML.
Frequently asked questions
What does "not well-formed" mean?
Does it check my XML against a schema (XSD or DTD)?
Why is some of my text not indented?
Why does cause an error?
Is my XML uploaded anywhere?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.