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

Opening and ending tag mismatch: fix it in an XML product feed

FeedAwake 5 min lesetid

An element was opened and not closed, or closed with a different name. XML parsers stop at the first one, so a single broken product makes the whole feed unreadable for Google Merchant Center, Meta and every other channel.

The message looks scary, but it already contains most of the answer: it names the tag that was left open, the line where it was opened and the closing tag the parser met instead.

What the error looks like

The same problem, reported by different tools (the examples below come from a feed where <title> on line 6 was never closed):

Chrome, Edge:   error on line 6 at column 26: Opening and ending tag mismatch: title line 6 and item
xmllint:        feed.xml:6: parser error : Opening and ending tag mismatch: title line 6 and item
PHP, lxml:      Opening and ending tag mismatch: title line 6 and item
Firefox:        XML Parsing Error: mismatched tag. Expected: </title>.
Python:         mismatched tag: line 6, column 20

Chrome, PHP (SimpleXML, DOMDocument, XMLReader) and Python's lxml all use libxml2, so they print the same text. Firefox and Python's built-in xml.etree use a different parser, expat, which says "mismatched tag". Expat counts columns from 0, so its column is one less.

How to read the message

Opening and ending tag mismatch: title line 6 and item has three parts:

  • title is the element that is still open.
  • line 6 is where that element was opened. This is usually where the mistake is.
  • item is the closing tag the parser found instead, </item>.

The position at the start ("error on line 6 at column 26") is where the parser noticed the problem. When the missing closing tag belongs to a long field, those two lines can be far apart. In a feed where a <description> opened on line 6 was never closed, the error is reported on line 7, at </item>:

error on line 7 at column 8: Opening and ending tag mismatch: description line 6 and item

Go to the line inside the message, not just the line at the start of it.

The five usual causes in product feeds

1. HTML in the description

By far the most common one. HTML allows <br> and <p> without a closing tag; XML doesn't. A description pasted from the shop's rich-text editor brings them along:

<description>Soft cotton.<br>Machine wash.</description>
Opening and ending tag mismatch: br line 6 and description

Fix: don't put raw HTML into XML. Either escape it (&lt;br&gt;), strip it, or wrap the whole value in CDATA, which the parser doesn't read as markup:

<description><![CDATA[Soft cotton.<br>Machine wash.]]></description>

A CDATA section can't contain ]]>. If a description might, escape instead.

2. A namespace prefix missing on one side

Google's attributes have a g: prefix. If a template opens <g:price> and closes </price>, the message is confusing because it drops the prefix:

Opening and ending tag mismatch: price line 6 and price

"price and price" looks like a match. It isn't: one is g:price, the other is price. Check both tags on that line for the prefix.

3. Different capitalisation

XML is case-sensitive, so <title> and </Title> are two different elements:

Opening and ending tag mismatch: title line 6 and Title

This usually comes from a hand-edited template or a field name typed differently in two places.

4. A template that opens a tag conditionally

A feed template prints <g:sale_price> inside an if and the closing tag outside it, or the other way round. Products with the condition met are fine; the rest break. If the error always points at the same attribute but only for some products, compare a broken product with a working one.

5. A value cut off in the middle of a tag

Some exports shorten long descriptions to a fixed length. If the cut lands inside HTML, <b>Size gu ends the description with an open <b>. The same happens when a value is truncated before being wrapped in CDATA and the cut removes the closing ]]>.

Fix: shorten text after stripping the HTML, or let an XML library write the file (see below).

Find the product behind the line

The feed line is not what you fix in the shop: you need the product. From the line in the message, scroll up to the nearest <item> (or <entry> in an Atom feed) and read its <g:id>. That's the product to open in your shop or plugin.

The free feed checker parses the feed the same way and lists the first errors with line and column, so you can do this without downloading a large file. If the feed is written on one line, see how to find the broken line: the column number is what you need there.

Only the first error matters. After a mismatch the parser loses track of which elements are open, so later errors are often just echoes of the first. Fix it and check again.

Stop it from coming back

Mismatched tags come from building XML by joining strings. An XML library (XMLWriter or DOMDocument in PHP, lxml in Python, any XML serializer in Node or Java) always closes what it opens and escapes text values, so this error can't happen. If a plugin or app generates your feed, send its developers the product ID, the line and the message: the bug is in their template, and fixing it there fixes it for every product.

A broken feed also doesn't announce itself. The shop keeps working while Merchant Center quietly stops reading the file. 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 of the first error. Or run a one-off check 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