Skip to content
Menu
Theme

XML Formatter and Validator

Format, minify or check XML in one box. Errors show the line and column, and entity tricks are refused for safety. Free, and it runs in your browser.

DeveloperRuns in your browser
Paste or type here. The result updates as you type.

 

What to do

What is an XML formatter?

An XML formatter takes XML that is squeezed onto one line, or indented in a messy way, and lays it out again so each element sits on its own line with clear indentation. XML still turns up everywhere: sitemaps, RSS feeds, e-invoices, SOAP replies, Android layouts, Office files and many bank and tax exports. Those files often arrive as one long string, and finding the tag you need by eye is slow work.

This tool does three jobs on the same input. Format rebuilds the XML with the indentation you pick under Indent: 2 spaces, 4 spaces or Tab. You can also untick Keep comments to drop the <!-- --> notes from the result. Minify removes the spaces and line breaks between tags, which gives you one compact line to paste into a request or a test. Check only tells you whether the XML is well-formed and shows “Valid XML.” when it is.

Every run checks the XML first. If a tag is not closed, two tags cross over or a name is misspelled in the closing tag, a message under the input points to the spot, for example “Line 3, column 14”. Attributes keep their order, text keeps its spaces, and CDATA sections and processing instructions stay as they were. Only the space between tags changes.

Some XML is made to attack the program reading it. The best-known case is called “billion laughs”: a few lines that declare entities, each one expanding into ten copies of the one before, until a tiny file grows into gigabytes of text and freezes the reader. Other entity tricks try to make the reader load files from the computer or the network. To stay safe, this tool refuses any XML that declares entities with <!ENTITY. It also stops at 1,000 levels of nesting, because a document that deep is almost always broken or hostile, and it never downloads anything a document points to.

Everything runs in your browser. Your XML is not uploaded, which matters when it holds invoice data, customer details or keys.

How to use the XML formatter

  1. Paste your XML into Your XML. The box starts with a short sample menu so you can see the result at once.
  2. Choose Format, Minify or Check under What to do.
  3. For Format, pick the Indent you like and decide whether to Keep comments.
  4. Read the output in the Result box, or the line “Valid XML.” after Check. If something is wrong, the message under the input shows the line and column to fix.
  5. Press Copy result and paste the text where you need it.

FAQ

Why does it say my XML is not well-formed?

The most common causes are a tag that is never closed, tags closed in the wrong order such as <b><i></b></i>, an HTML-only name such as &nbsp;, or two top-level elements where XML allows only one. Go to the line and column in the message and look just before that spot.

Why does it reject my file with an ENTITY declaration?

Entity declarations can blow a small file up into a huge one, or ask the reader to open files it should not touch. The tool cannot tell a harmless declaration from a harmful one quickly and safely, so it refuses them all. Remove the <!ENTITY lines and replace each entity in the text with the value it stood for.

Why is   an error?

&nbsp; comes from HTML, not XML. XML only knows &amp;, &lt;, &gt;, &quot; and &apos;. Use the number form &#160; or a plain space instead.

Is there a limit on size or depth?

The box takes up to 200,000 characters, and nesting can go 1,000 levels deep. When the result is very long, the box shows the first part only, but Copy result always copies everything.

Will formatting change my data?

No. Element names, attributes, their order and the text inside elements stay the same. Numbered character codes such as &#233; are written out as the letter they stand for, which means the same thing to any XML reader.

Is my XML sent or stored anywhere?

No. All the work happens inside the page on your own device, and nothing is kept after you close the tab.

Related tools