XML Formatter

You have some XML that will not work and something telling you it is invalid without saying where. Paste it below and this xml formatter will tell you the line, the column, and what is actually wrong.

If what you are actually holding is a broken RSS feed or a sitemap that a search engine has started refusing, do not worry, that is the commonest reason anybody ends up on a page like this. It is also usually one very small thing, and there is a good chance it is the one covered first below.

Nothing you paste leaves your browser. The checking happens on your own computer, so there is no upload and nothing stored.

Nothing to check yet. Paste something above, or press Example.

Checked in your browser. Nothing is uploaded, and nothing is stored.

The bare ampersand, which breaks more feeds than everything else together

If your feed or sitemap worked yesterday and does not today, check this first. It is right almost every time.

An & on its own is not allowed in XML. Not in a title, not in a description, not anywhere. It has to be written as &.

<title>Smith & Sons</title>       breaks the whole file
<title>Smith &amp; Sons</title>   is correct

The reason it catches people out is the timing. Nothing changed in your setup. Somebody simply published a post with an ampersand in the title, or added a company name to a page, and from that moment the feed containing it is broken.

The tool spots these, points at the exact one, and offers to escape them all for you.

Where it stops. If a plugin or a template is producing the unescaped ampersand, fixing the file here fixes the copy in front of you and not the cause. The next time that page is regenerated it will come back. Use this to identify what is wrong, then fix it at the source.

Well formed is not the same as valid, and this matters

Nearly every page calling itself an XML validator is not one, and the difference is the reason people get told their file is fine and then have it rejected anyway.

  • Well formed means the XML rules are obeyed. Tags match and close in the right order, there is one outermost element, the special characters are escaped, quotes are where they should be. That is what this page checks.
  • Valid means the document also matches a schema: a separate file saying which elements are allowed, where, in what order and how many times. An RSS feed being valid means it has the elements RSS requires.

Think of it like a letter. Well formed is that the sentences are grammatical and the envelope is sealed properly. Valid is that it is the right letter, containing the things this particular recipient insists on. A perfectly grammatical letter can still be the wrong one.

Where it stops, and it is worth being blunt. No tool can tell you a document is valid unless you give it the schema, and almost none of the pages claiming to validate XML ask you for one. So this page says well formed, because that is what it checked. If a system is still refusing your file after this says it is well formed, the problem is which elements are in it, not how they are written.

The mistakes it names for you

  • A bare ampersand. Covered above. Far and away the most common.
  • Tags closed in the wrong order. <a><b></a></b> is wrong. The last one opened must be the first one closed. The tool tells you which tag is still waiting and which line it started on.
  • A tag never closed at all. It names the tag and the line it opens on, which is usually far away from where you were looking.
  • Two outermost elements. An XML document holds exactly one. This catches people who have joined two files together.
  • An attribute with no quotes. HTML allows id=1. XML never does.
  • An attribute with no value. HTML allows <input disabled>. XML never does.
  • The same attribute twice on one tag. HTML quietly keeps the first. XML refuses the file.
  • An entity XML does not know. &nbsp; is an HTML thing. XML knows only five by name and everything else has to be a number, such as &#160;.
  • A double hyphen inside a comment. Which catches anybody who draws a line of dashes as a separator.
  • The declaration not being first. <?xml ... ?> must be the very first thing, before any blank line. A stray space in a template is a classic cause.
  • An invisible mark at the start. Some Windows editors add one when saving. You cannot see it and plenty of readers reject the file on character one.

The five characters that have to be escaped

These five have a meaning in XML, so writing them literally confuses the reader:

&   becomes   &amp;      always, everywhere
<   becomes   &lt;       always, everywhere
>   becomes   &gt;       in practice, be safe
"   becomes   &quot;     inside a double quoted attribute
'   becomes   &apos;     inside a single quoted attribute

The other way to handle awkward text is CDATA, which tells the reader to take everything inside literally. RSS feeds use it constantly for content with HTML in it.

Where it stops. CDATA is not a way out of everything. The sequence ]]> cannot appear inside one, because that is how it ends. It is rare, and when it happens it is baffling, so it is worth knowing.

Frequently asked questions

Is my XML sent anywhere?

No. It runs in your browser and there is no upload of any kind. Open your browser’s developer tools, go to the Network tab, and paste something in. Nothing is sent. You can also disconnect from the internet and it carries on working.

My RSS feed is broken. Where do I actually start?

Open the feed in your browser, use view source, copy the whole thing and paste it in here. That gets you the line number.

Nine times in ten it is a bare ampersand in a post title. Find the post, fix the title, and the feed comes back on its own.

If the problem turns out to be a blank line or a space before the <?xml at the top, that is usually a plugin or theme file with a stray line after its closing PHP tag. That one is genuinely annoying to track down and the culprit is nearly always something recently activated.

Can it check my sitemap?

Yes, a sitemap is XML like anything else, and this will tell you whether it is well formed.

It will not tell you whether the URLs in it are right, whether they return a page, or whether a search engine will like it. Those are all real problems and none of them are XML problems.

Why does formatting change my line breaks?

Because indenting means putting line breaks and spaces between tags, and that whitespace is part of the document.

For nearly everything, including feeds and sitemaps, this does not matter at all and readers ignore it. It matters if some system is treating the space inside an element as meaningful content. If you are in that situation, use Minify rather than Format, which puts everything back on one line.

An element holding nothing but text is kept on one line on purpose, so a feed stays readable rather than being blown across three lines per title.

Will it fix things for me?

Only the ampersands, and it lists what it changed.

It deliberately will not guess at missing tags. When a tag is unclosed there is usually more than one place the closing one could go, and the versions mean genuinely different things. A tool that silently picks one is worse than a tool that admits it does not know which you meant.

If you have any issues, you can ask me via comment, and I will love to help you out.