CorrectFeed

RSS feed invalid XML error — how to fix parsing failures

An “invalid XML” error usually means your feed output contains one character or one broken tag that makes the whole document unparsable.

Fast diagnosis (find the first real error)

Most validators report the first parse error and stop. Fix that one, re-run validation, then repeat — multiple issues are common.

If you have a line/column number, go straight there and inspect a few characters before and after the reported position.

Common parser errors (and what they usually indicate)

Error you might seeUsually meansMost common fix
EntityRef: expecting ';'Unescaped & in text or attributesReplace & with &
not well-formed (invalid token)Invalid control character or bad encodingRemove invalid characters; ensure UTF‑8
mismatched tagBroken markup (missing closing tag)Fix or sanitize the offending entry’s HTML/text
XML declaration allowed only at the start of the documentExtra bytes before <?xml ...?> (BOM/whitespace)Ensure the XML declaration is the first bytes in the response

1) Unescaped characters (the classic)

In XML text, characters like & must be escaped as &amp; (unless inside a correct CDATA section).

Typical offenders:

  • titles containing AT&T, R&D, etc.
  • URLs pasted into text nodes without escaping
  • HTML snippets inserted into <description> without CDATA/escaping

A quick example

Bad:

<title>R&D updates</title>

Good:

<title>R&amp;D updates</title>

Another common trap: HTML entities like &nbsp;

In XML, named entities like &nbsp; are not valid unless defined in a DTD (feeds generally don’t use one). Use the actual character, or a numeric reference like &#160;.

2) Control characters and encoding issues

Some CMSes accidentally output invalid characters (often copied from rich text editors).

If the XML declares UTF‑8 but the content is not valid UTF‑8, parsers will fail.

Things to check:

  • Make sure the XML header declares the real encoding (typically UTF‑8).
  • Remove null bytes and other invalid control characters (often invisible).
  • Avoid mixing encodings (e.g. a Windows-1252 byte in a UTF‑8 document).

3) Broken CDATA

CDATA sections must be closed properly. A stray ]]> can break the document.

4) Mismatched tags and malformed markup inside items

One broken entry can break the whole feed:

  • missing closing tags like </description>
  • <content:encoded> containing unclosed HTML
  • accidentally embedding raw <script> or <style> blocks

If you include HTML in RSS <description> or <content:encoded>, make sure it’s either:

  • properly escaped as text, or
  • wrapped in a valid CDATA section
  1. Validate the feed and note the first error (line/column if available).
  2. Fix that error, then re-validate — multiple issues are common.
  3. Once the XML parses cleanly, check platform-specific validators (Apple Podcasts, Spotify) if it’s a podcast feed.

Prevent repeat failures

  • Generate XML with a real XML serializer (not string concatenation).
  • Sanitize user-provided content (titles/descriptions) before inserting into XML.
  • Keep your feed output minimal and well-formed; avoid injecting scripts, trackers, or complex HTML.
  • Add a quick CI check that fails builds if the feed is not well-formed XML.

FAQ

Why does my RSS feed have an invalid XML error?

Most commonly: unescaped ampersands, invalid control characters, broken CDATA sections, malformed tags, or mixed/incorrect encoding declarations.

What does 'EntityRef: expecting ;' mean?

It often means an ampersand (&) was used without being escaped as &amp; in an XML text node or attribute.

Is one bad item enough to break the feed?

Yes. Many parsers reject the entire feed if any part of the XML is malformed.

Fix RSS/Atom feeds and OPML lists

Paste a feed/OPML URL, upload a file, or paste XML — then validate and fix it.

Fix my feed / Import OPML Back to Help