Denne artikkelen er foreløpig bare tilgjengelig på engelsk.

XML feed parse error: how to find the broken line in your product feed

FeedAwake 7 min lesetid

An XML product feed is all or nothing. Thousands of products can be perfect, but one unescaped character in one product title makes the file invalid XML — and a parser that can't read the file can't read any of it. Google Merchant Center, Meta and every other channel will report the feed as unreadable, and depending on where the break is, they process nothing or only the products before it.

The fix is usually a single character. The hard part is finding it in a file with fifty thousand lines. This guide shows how to find it quickly and what usually causes it.

Step 1: get the line and column

Every XML parser stops at the first problem and knows exactly where it is: a line number and a column (the position within that line). You need those two numbers, plus the parser's message.

The quick way. Paste the feed URL into the free feed checker. It downloads the feed, parses it and lists the errors with their position, for example:

XML line 3, column 19: xmlParseEntityRef: no name

On your own computer. If you have the file, xmllint (part of libxml2, preinstalled on macOS and most Linux systems) does the same:

xmllint --noout feed.xml

No output means the file is well-formed. Otherwise it prints the line, the message and the spot it choked on.

Then open the file at that position. Most code editors have "Go to line" (Ctrl+G in VS Code, then line:column). Don't use a browser or a spreadsheet: they hide exactly the characters that cause trouble.

Two things that make this harder

  • Only the first error matters. After the first problem the parser is confused, so the errors after it are often just consequences. Fix the first one and check again.
  • Feeds written on one line. Many generators write the whole file without line breaks, so every error is on "line 1, column 2,483,917". Your editor can still jump to that column; or pretty-print a copy of the file — after the break is fixed, because a formatter can't format invalid XML either.

Step 2: recognise the cause

The parser's message tells you what kind of problem it is. These are the eight that break product feeds most often.

1. An unescaped ampersand

The most common one by far: Tom & Jerry mug, Black & white, or a URL with parameters like ?color=red&size=m. In XML, & starts a special sequence, so on its own it is an error. The parser says something like xmlParseEntityRef: no name.

Fix: write & instead of & — in text and in URLs alike — or wrap the text in a CDATA section, which XML doesn't parse:

<title>Tom &amp; Jerry mug</title>
<description><![CDATA[Tom & Jerry mug — <b>dishwasher safe</b>]]></description>

2. A < or > inside text

Size < 40 cm or HTML from the product description pasted straight into the feed. A < starts a tag, so the parser expects one and finds text.

Fix: &lt; and &gt;, or CDATA for anything that may contain HTML.

3. The wrong encoding

The file says it is UTF-8 (or doesn't say, which means UTF-8), but some text was saved in another encoding — typically product names with é, ü, ø or curly quotes copied from an old system. The message looks like Input is not proper UTF-8, indicate encoding.

Fix: make the whole export UTF-8, end to end: the database connection, the script and the file. Don't just change the declaration at the top — the bytes have to match it.

4. Invalid control characters

Text copied from Word, PDFs or old databases can carry invisible characters (a vertical tab, a "unit separator"…) that XML 1.0 doesn't allow at all, escaped or not. The error points at a spot where you see nothing.

Fix: strip characters below code point 32 except tab, line feed and carriage return before writing the feed.

5. A missing Google namespace

Google's attributes are written as <g:id>, <g:price>, <g:image_link>. That g: prefix has to be declared once at the top of the file. Without the declaration, a namespace-aware parser stops with Namespace prefix g on id is not defined.

Fix: declare it on the root element:

<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">

6. A truncated file

The file just stops in the middle of a product. The export ran out of time or memory, the disk was full, or Google downloaded the file while the export was still writing it. This one is nasty because it comes and goes: the file you open in the morning is complete, the one Google fetched at night was not.

Fix: write the feed to a temporary file and rename it to the real name only when it is complete — a rename is instant, so nobody can download a half-written file. And find out why the export is slow or crashing.

7. Something before the XML declaration

<?xml version="1.0"?> must be the very first thing in the file. A blank line, a stray character or a PHP warning printed before it makes the whole file invalid ("XML declaration allowed only at the start of the document").

Fix: make sure nothing is printed before the XML — check for debug output, warnings and spaces before the opening tag in template files.

8. A tag opened in one place and closed in another

Opening and ending tag mismatch usually means a product's template is broken for one case — an optional field left open, an if around an opening tag but not around its closing tag. Look at the product at the reported line and compare it with one that works.

A note on "it's valid, but there are no products"

Sometimes the file is perfectly valid XML and still breaks everything: the server answered with an HTML page instead of the feed — a login page, a "403 Forbidden", a bot-protection challenge from Cloudflare or a security plugin. The parser is happy, but there are zero products. If Merchant Center suddenly sees no items, open the feed URL in a private window and check what it actually returns.

Generate the feed so it can't break

Most of these problems come from building XML by gluing strings together. An XML library (DOMDocument or XMLWriter in PHP, lxml in Python, any serializer in Node) escapes &, < and > for you, writes the encoding correctly and always closes what it opens. If your feed is built by a plugin, report the broken product to its developers with the line and message — they can fix the escaping for everyone.

Catch it the night it happens

A broken feed doesn't announce itself. The store keeps working, the ads keep running, and you find out when Merchant Center shows the products as disapproved — often a day later, and for a truncated file maybe only sometimes.

FeedAwake checks your feed on a schedule — as often as every 15 minutes — parses it like a channel does, and alerts you by email, Telegram, Slack or Discord when it breaks, with the line, column and message of the first errors, so you can go straight to the fix. It also tells you when the feed URL returns an error or a page with no products at all. You can try it on your own feed with a 14-day free trial, no credit card needed.

Or check it once, right now, with the free feed checker.

Sjekk produktfeeden din gratis

Finn feil i feeden før de koster deg annonsebudsjett. Ingen konto nødvendig.

Start din gratis prøveperiode på 14 dager Gratis Merchant Center-gjennomgang

Flere artikler