XML Formatter: beautify, minify and check XML online
Input
Output
What is XML?
XML (eXtensible Markup Language) is a text format for structured data that wraps every value in named tags, like <name>Asha</name>. JSON has taken over most web APIs, but XML is still everywhere else: SOAP services, RSS and Atom feeds, sitemaps, SVG images, Android layouts, Maven and .NET project files, Office documents, and a great deal of banking and government data exchange.
An XML document has exactly one root element, and every element inside it either closes (<a>…</a>) or closes itself (<a/>). Tags must close in the reverse order they opened, attribute values must be quoted, and the characters < and & have to be written < and & in text. Breaking any of those rules makes the document not “well-formed”, and a parser will refuse it outright.
Why use an XML formatter?
XML sent between machines usually arrives as a single line. A formatter turns it back into a tree a person can read, and tells you along the way whether it is well-formed at all:
- Readability. Indentation shows what is nested inside what, which in a deep SOAP envelope or a config file is most of what you need to know.
- Debugging. A tag closed in the wrong order or a bare
&in a product name is hard to find by eye. The error here names the line and column, and for a mismatched tag also the line where the other one opened. - Size. Minifying removes the indentation and line breaks between tags, for a payload or a config value that has to be as small as possible.
Example
<student id="42" batch="DA-11"><name>Asha Rao</name><email>asha@example.com</email><courses><course>SQL</course><course>Python</course></courses><bio>Moved from <b>finance</b> to analytics.</bio><mentor/></student><student id="42" batch="DA-11">
<name>Asha Rao</name>
<email>asha@example.com</email>
<courses>
<course>SQL</course>
<course>Python</course>
</courses>
<bio>Moved from <b>finance</b> to analytics.</bio>
<mentor/>
</student>Note the <bio> line. It mixes text with a <b> tag, so it stays on one line: breaking it up would put new spaces into the sentence. With Attributes on Separate Lines on and Empty Elements set to <tag></tag>:
<student
id="42"
batch="DA-11"
>
<name>Asha Rao</name>
<email>asha@example.com</email>
<courses>
<course>SQL</course>
<course>Python</course>
</courses>
<bio>Moved from <b>finance</b> to analytics.</bio>
<mentor></mentor>
</student>About Gradient Learning's XML Formatter
It is free, needs no sign-up, and runs entirely in your browser: the document you paste is never uploaded, stored or logged, and the page keeps working if you go offline after it loads. XML tends to be the format of internal systems, so what people paste is often a real invoice, a customer record or a service's configuration.
It changes layout and nothing else. In particular:
- Values are copied as written. Attribute values keep their quotes, entities like
&stay entities, and CDATA sections are passed through untouched. - Mixed content keeps its spaces. An element that holds text and tags together is kept on one line, exactly as written.
xml:space="preserve"is respected. An element carrying it, and everything inside it, is copied across character for character.
The one thing it does change is whitespace at the two ends of an element that holds only text, so <name> Asha </name> becomes <name>Asha</name>. That whitespace is almost always indentation from a previous formatter; if it matters in your document, mark the element xml:space="preserve".
How to use the tool
- Paste your XML into the input panel on the left, or open a file.
- The formatted document appears in the output panel on the right as you type. There is nothing to click. If it is not well-formed, a strip across the top of the output names the problem and its line and column; press the position to jump the cursor to it.
- Switch between Beautified and Minified, set the indentation, then use the copy or download button on the output panel.
Formatting options
Basic options (always visible)
| Option | What it controls | Possible values |
|---|---|---|
| Output | Whether to indent the document or strip it to one line | Beautified, Minified |
| Indentation | Width of one indent level in the beautified output | 2, 3 or 4 spaces, Tabs |
| Empty Elements | How an element with no content is written. The two forms mean the same thing to every XML parser | As written, <tag/>, <tag></tag> |
Advanced options (under “More”)
| Option | What it controls | Possible values |
|---|---|---|
| Attributes on Separate Lines | Gives each attribute its own line when a tag has more than one | On, Off |
| Keep Comments | Whether <!-- comments --> are kept in the output | On (default), Off |
Frequently asked questions
Is the Gradient Learning XML Formatter safe to use?
Yes. It runs entirely in your browser, so the document you paste is never uploaded, stored or logged, and the page keeps working if you go offline after it loads. XML is usually the format of internal systems, so what people paste is often a real invoice, customer record or service configuration.
Does it validate my XML as well as format it?
It checks that the document is well-formed: one root element, tags that close in the right order, quoted attribute values, no duplicate attributes, and no bare < or & in text. When something is wrong you get one sentence saying what, the line and column, and a squiggle under that character in the editor. The last output that worked stays on screen while you fix it. It does not validate against a DTD or an XML Schema (XSD).
Why is my XML not well-formed?
The usual causes are a closing tag that does not match the one that opened (often a typo or a tag closed in the wrong order), a bare & in text such as a company name, which has to be written &, an attribute value without quotes, and a second root element when two documents were pasted together. The error message names which one it is.
Will formatting change my data?
Only in one place. Attribute values, entities and CDATA sections are copied exactly as written, and an element that mixes text with tags is kept on one line so no spaces are added inside a sentence. What is removed is the whitespace at the start and end of an element that holds only text, which is almost always leftover indentation. Mark an element xml:space="preserve" and it is copied character for character.
What is the difference between beautifying and minifying?
Beautifying puts each element on its own line and indents it by depth, so a person can read the tree. Minifying removes the whitespace between tags so the document is as small as possible. Neither changes what the document means, so you can switch back and forth freely.
Does it support namespaces, CDATA and DOCTYPE declarations?
Yes. Namespaced tags and attributes such as soap:Envelope and xmlns:g are kept as written, CDATA sections are passed through untouched, and the XML declaration, a DOCTYPE with an internal subset, comments and processing instructions all stay where they were.
Is there a size limit?
Not on what you paste, but a file you open has to be under 1 MB. Past that the editor itself becomes slow, which is a worse experience than being told no. Formatting runs in a background thread, so a large document does not freeze the page while it works.