You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XML解析格式无效问题:为何部分商品链接报错及修复方法

Fixing XML Parsing Error: not well-formed (For Sitemap URL Issues)

Hey there, let's break down why your product_id=8111 URL works fine in the sitemap but product_id=1100 throws a parsing error. The root cause almost always boils down to unescaped special characters in the URL—XML is super strict about this!

Why the Discrepancy?

Look at your working URL:

<loc>http://localhost/index.php?route=product/product&amp;product_id=8111</loc>

Notice the &amp; instead of a plain &? That's the key. XML treats & as the start of an entity reference (like &amp; itself), so if you write a raw & in your URL, the parser gets confused—it thinks you're trying to reference an XML entity that doesn't exist, hence the "not well-formed" error.

Chances are your product_id=1100 link looks like this (which is invalid):

<loc>http://localhost/index.php?route=product/product&product_id=1100</loc>

The raw & here breaks XML parsing entirely.

Other possible (though less likely) issues:

  • The URL contains other forbidden XML characters like <, >, ", or ' without escaping
  • There are hidden spaces or weird invisible characters at the end of the URL

Step-by-Step Fixes

  1. Escape All Special Characters in URLs
    For sitemap URLs, you must escape these characters to comply with XML rules:

    • & → &amp; (this is the one tripping you up)
    • < → &lt;
    • > → &gt;
    • " → &quot;
    • ' → &apos;
      Your corrected product_id=1100 line should be:
    <loc>http://localhost/index.php?route=product/product&amp;product_id=1100</loc>
    
  2. Validate Your Entire Sitemap
    After fixing the URLs, run your sitemap through an XML validator to catch any other syntax issues. You can use local XML validation tools to avoid sharing sensitive site data.

  3. Automate Escaping If You Generate Sitemaps Programmatically
    If your sitemap is auto-generated (e.g., with PHP), add a step to escape URLs before writing them to XML. In PHP, the htmlspecialchars() function with the right flags does this perfectly:

    $raw_url = "http://localhost/index.php?route=product/product&product_id=1100";
    $escaped_url = htmlspecialchars($raw_url, ENT_XML1, 'UTF-8');
    echo "<loc>{$escaped_url}</loc>";
    

    This ensures you never forget to escape special characters manually.

Quick Extra Check

You already have the correct encoding="UTF-8" declaration at the top of your XML, which is great. One tiny note: while your <lastmod> format (2019-05-13 13:07:07) won't cause parsing errors, the official sitemap protocol recommends using the YYYY-MM-DDThh:mm:ssTZD format (e.g., 2019-05-13T13:07:07+00:00) for better compatibility with search engines.

内容的提问来源于stack exchange,提问作者Ivan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:07:00