Den här artikeln finns för närvarande bara på engelska.

xmlParseEntityRef: no name and EntityRef: expecting ';' in an XML feed

FeedAwake 4 min läsning

Both messages mean the same thing: there is a bare & in the feed. In XML, & starts a reference such as & or <, so a parser that meets one expects a name and a semicolon after it. When they aren't there, it stops, and the whole feed becomes unreadable for Google Merchant Center, Meta and other channels.

The two messages differ only in what follows the &, and that tells you where to look.

Which message, which cause

Chrome, PHP, lxml, xmllint:  xmlParseEntityRef: no name
                             EntityRef: expecting ';'
                             Entity 'nbsp' not defined
Firefox:                     XML Parsing Error: not well-formed
                             XML Parsing Error: undefined entity
Python (xml.etree):          not well-formed (invalid token): line 5, column 12
                             undefined entity: line 5, column 10

In Chrome and Edge the line starts with "error on line 5 at column 13:". The first three messages come from libxml2, which Chrome, PHP and Python's lxml share. Firefox and Python's built-in parser use expat, which reports all bare ampersands as "not well-formed".

xmlParseEntityRef: no name: the & is followed by a space or a character that can't start a name. Typical in product text:

<title>Tom & Jerry mug</title>

EntityRef: expecting ';': the & is followed by letters, so the parser read a name, but no ; came after it. Typical in URLs with parameters and in words joined with &:

<link>https://shop.example/p/1?color=red&size=m</link>
<title>Black&White tee</title>

Entity 'nbsp' not defined: the & and the ; are both there, but the name is an HTML entity. XML knows only five: &amp;, &lt;, &gt;, &quot; and &apos;. Descriptions copied from a web page bring &nbsp;, &eacute;, &mdash;, &trade; and the rest.

The fix

Write every literal & as &amp;:

<title>Tom &amp; Jerry mug</title>
<link>https://shop.example/p/1?color=red&amp;size=m</link>

This doesn't break URLs. &amp; is how XML writes an ampersand. The parser turns it back into & before Google or Meta read the value, so they get ?color=red&size=m, exactly the URL you meant. Don't replace it with %26: that's a different URL, where size=m becomes part of the colour value.

For HTML entities, write the character itself (the feed is UTF-8, so é, — and ™ are fine as they are) or a numeric reference, which XML accepts:

<title>Café crème mug</title>
<description>Café crème&#160;mug</description>

&#160; is the non-breaking space that &nbsp; meant.

For descriptions full of HTML, a CDATA section avoids escaping altogether: inside it &, < and > are plain text.

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

Don't escape twice

The usual follow-up problem: the feed now parses, but titles in Google show Tom &amp; Jerry. The text was escaped once in the shop or database and again when the feed was written, so the file contains &amp;amp;. The parser turns that into the literal text &amp;, and that's what shoppers see.

Escape exactly once, at the moment the XML is written. If product names are stored with &amp; in your database, decode them before the feed escapes them.

Find the product

Open the feed at the line and column from the message and scroll up to the nearest <item> and its <g:id>. A bare ampersand is usually in that product's title, description, link or image URL. The free feed checker lists the first errors with line and column. If the whole feed is on one line, this guide shows how to jump to the column.

There is rarely only one. The same product name or URL pattern usually appears in many products, and the parser only reports the first. After fixing one, search the file for & and for & followed by letters that aren't one of the five XML names.

Make it impossible

Ampersand errors come from writing XML by gluing strings together. An XML library (XMLWriter or DOMDocument in PHP, lxml in Python, any XML serializer in Node or Java) escapes &, < and > for you, exactly once. If a plugin builds your feed, report the product ID and the message to its developers: one escaping fix in the template covers every product.

The error also tends to arrive with new products, not with a release: one new title with an & in it is enough. FeedAwake checks the feed on a schedule and alerts you by email, Telegram, Slack or Discord when it stops parsing, with the line and message, so you hear about it before Merchant Center starts rejecting the feed. To check it once, use the free feed checker.

Kontrollera ditt produktflöde gratis

Hitta flödesfel innan de kostar dig annonsbudget. Inget konto behövs.

Starta din kostnadsfria provperiod på 14 dagar Gratis Merchant Center-granskning

Fler artiklar