XML Formatter and Validator

Indent a wall of XML into something a person can read, squash it back down when you are done, and get the line and column when it refuses to parse at all rather than a bare error.

How to use it

In the indent direction every element goes on a line of its own, except short text elements, which are kept whole rather than split across three lines for the sake of consistency.

  1. Paste it, or drop a file Anything the browser reads as XML — RSS, a sitemap, SOAP, a settings file, an SVG.
  2. Choose tidy or minify Tidy for reading, minify for sending.
  3. Set the indent Two spaces is the usual. Zero puts every element on its own line with no leading space at all.
Full instructions
Spaces

Your XML

Result

In depth

Turning unreadable XML into something you can follow

What tidy and minify actually do to a document, how every setting on the page changes the output, a full walkthrough with broken markup, and the difference between a well-formedness check and a schema check.

Screenshot: About the XML formatter
About the XML formatter as it appears when the page opens.

Two opposite jobs, one text area

XML is everywhere and almost nobody writes it by hand. It arrives as a single enormous line from an API, a config export, or a log dump, and you need to read it. Or it arrives nicely indented and you need to squash it flat for a POST body or a deployment file. This page does both.

Paste the markup into the left pane and the formatted result appears in the right pane. If the document is broken, you do not get a result at all. You get a red status line that names the exact line and column where the parser gave up. That is not a side feature. For many people it is the whole reason they came.

Getting your XML in

Three ways to load a document. The most common is to paste it straight into the text area labelled Your XML. The second is to press Open a file and pick a file from disk. The third is to drag a file and drop it onto the input pane.

The page reads anything your browser treats as XML. That includes RSS feeds, sitemaps, SOAP envelopes, Android layout files, Maven POMs, SVG drawings, and .config files from the .NET world. If the file ends in .xml, .svg, .rss, or .xsl, it will open. If it is plain HTML with unclosed tags, it will not, because HTML is not XML.

Press Try an example to load a small sample document. It is useful the first time you visit, and it is handy for checking that your settings produce the output shape you expect before you paste the real thing.

The Mode dropdown

Mode offers two choices. Tidy it up takes the document and writes it out with each element on its own line, nested according to depth, with the number of spaces you choose. Short text content stays on the same line as its opening and closing tags. This is the default, and it is the one that turns a wall of angle brackets into something a person can scan.

Squash to one line does the opposite. Every line break and every run of whitespace between tags is removed. The document comes out as a single unbroken line. Use this when you need to drop a document into a request body, a database field, or any slot that expects the markup to carry no formatting of its own.

Indent, comments, and the declaration

The Indent field sets how many spaces each nesting level adds. Two is the most common choice and the default. Four is popular in Java projects. Zero puts each element on its own line with no leading space, which is occasionally useful when you want to see the tree structure but do not want to scroll sideways on a deep document.

Keep comments is a checkbox, on by default. Turn it off and every comment block is stripped from the output. This is often what you want when you are minifying, because comments add bytes that nobody on the receiving end will read.

Keep the XML declaration is another checkbox, also on by default. The declaration is the line at the top that reads something like xml version 1.0 encoding UTF-8. Some systems require it, others choke on it. Toggle the checkbox and see the result change in real time.

Reading the status line

The bar at the bottom of the input pane changes colour depending on what it finds. Green means the document parsed successfully. It also shows a count of the elements and attributes in the document, which is a quick way to confirm you pasted the whole thing.

Red means the document is broken. The message names the line number and the column where the parser stopped. Common causes are an unclosed tag, a stray ampersand that was not written as an entity, a second root element, or a byte order mark before the declaration that looks invisible but the parser cannot ignore.

The status updates as you type or edit. Fix the reported line and the status goes green again, often revealing a second problem further down. Work through them one at a time and the document will eventually parse.

The result pane

When the input is valid, the right pane fills with the formatted output. Two buttons sit at the top. Copy puts it on the clipboard. Download saves it as a file. Both give you exactly what you see in the pane, so what you copy is what you paste.

A row of small chips at the bottom of the result pane shows counts. Elements, attributes, and the total size in characters. If the document shrank or grew after formatting, the size difference tells you how much whitespace was added or removed.

The result is read-only, so you cannot accidentally edit it and wonder why the copy does not match. If you need to make changes, work in the input pane on the left. The right pane always reflects the latest valid parse of whatever is on the left.

Walking through a broken document

A colleague sends you an XML export that will not load into your application. You paste it into the input pane and the status line turns red: line 47, column 12. You scroll down and find that an ampersand in a company name was written as a bare character instead of the entity. You fix it, and the status goes green.

You switch Mode to Tidy it up, leave Indent at two, and read through the structure. You notice a section near the bottom is nested one level too deep. You fix that in the input pane. The result pane updates and the tree looks right. You press Copy, paste it into your application, and it loads.

The whole job took two minutes. Without the line number, you would have been staring at three thousand characters on a single line trying to spot a missing bracket by eye.

Things the formatter does not do

It checks well-formedness, not schema validity. A well-formed document has every tag closed, every entity written properly, and exactly one root element. That is all the XML specification requires. Whether your feed has the right fields for a particular reader, or whether your config file has the keys your application expects, is a question about the schema, and answering it needs the schema file as well.

It does not format HTML. Ordinary HTML has void elements like img and br that never close, and it has optional closing tags that XML forbids. If you paste regular HTML you will get a red status line, and the right tool is the HTML formatter instead.

It does not reorder attributes or rename namespace prefixes. Both of those would produce a document that is technically equivalent but may break software that reads the markup by position or by prefix name.

CDATA and mixed content

A CDATA section is a block that can contain angle brackets and ampersands without escaping them. Formatting XML with a regular expression or a text search will eventually damage one of these, because the tool sees a bracket and thinks it found a tag. This formatter uses the browser's own XML parser, so CDATA blocks pass through exactly as they went in.

Mixed content is a different kind of tricky spot. When an element holds both plain text and child elements on the same line, adding whitespace would change the content of the document. The formatter leaves these elements on a single line rather than risking a space that was not there before.

The document never leaves your browser

The parsing and formatting happen inside the page itself. Nothing is sent to a server, there is no account, and the page works offline after it has loaded once. You can verify this by opening the network tab in your browser's developer tools and watching that no requests go out when you paste and format.

For a config file that holds database credentials, or a SOAP message with customer records, that matters. The document stays on your device, and closing the tab is the end of it.

Help

About the XML formatter

In the indent direction every element goes on a line of its own, except short text elements, which are kept whole rather than split across three lines for the sake of consistency. Minify squashes the same document back onto one line for a config value or a request body. Both directions parse before writing anything, so a stray tag stops the tool rather than producing plausible rubbish.

Paste it, or drop a file

Anything the browser reads as XML — RSS, a sitemap, SOAP, a settings file, an SVG.

Choose tidy or minify

Tidy for reading, minify for sending.

Set the indent

Two spaces is the usual. Zero puts every element on its own line with no leading space at all.

Read the status line

Green means it parsed, with a count of elements and attributes. Red gives you the line and column where it gave up.

Copy or download

The result never leaves your device either way.

Runs on your device

The XML is parsed and formatted inside this page. Nothing is uploaded, there is no account, and once the page has loaded it works offline.

Good to know

Text mixed with tags is left exactly as written

In a line like a paragraph holding both words and a bold tag, the spaces around the tags are part of what the document says. Indenting that would change the content, so any element holding both text and child elements is reproduced unchanged.

CDATA survives

A CDATA section can legally contain angle brackets, which is why formatting XML with a search and replace eventually mangles one. This uses the browser’s own parser, so a CDATA block comes out exactly as it went in.

This is a well-formedness check, not a schema check

It tells you the document is valid XML — tags matched, one root, entities closed. It cannot tell you whether your feed has the fields a reader expects, because that needs the schema as well.

Namespace prefixes are kept

A prefix and its declaration are preserved as written. Renaming prefixes would still be valid XML and a different document to anything reading it by prefix.

Common questions

Does it check against a schema or DTD?
No. It checks the document is well formed — every tag closed and nested properly, one root element, entities valid. Checking against an XSD or DTD is a different job and needs that file too.
Why did my comments disappear?
Turn "Keep comments" on. With it off they are dropped, which is usually what you want when minifying for a request body.
Will it break my CDATA?
No. CDATA sections are passed through untouched, brackets and all.
Can it format HTML?
Only if the HTML is also valid XML, which is to say XHTML. Ordinary HTML has unclosed tags that XML rules forbid, so use the HTML tools for that.
Why does it say line 1 for a file that looks fine?
A stray character before the declaration counts — a byte order mark, or a blank line. So does a second root element, which is reported where the second one starts.
Is my XML uploaded anywhere?
No. It is parsed by your own browser and never leaves the device.
Is it free?
Yes, with no account and no limit on how much you format. Ads on the page pay for the site.