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

Android Studio编译XML报错:URL中&符号致格式无效求助

Fix XML Validation Error for URLs with & in Android Studio

Alright, I’ve been in your shoes dealing with XML validation errors for unmodifiable URLs (especially Amazon affiliate links like yours). Here’s the simplest, safest fix to get past the error without changing your URL content:

Wrap the URL in a CDATA Section

XML parsers flip out when they see entity-like strings even if they’re escaped properly, but a CDATA section tells the parser to treat everything inside as plain text—no parsing, no validation checks for markup. Perfect for your case since you can’t alter the URL.

Here’s Your Modified XML

<?xml version="1.0" encoding="UTF-8"?>
<Items>
    <Item>
        <DetailPageURL>
            <![CDATA[https://www.amazon.de/Chemie-76128-Felgenreiniger-Alu-Teufel-Spezial/dp/B004LAXG9C?psc=1&amp;SubscriptionId=mykey&amp;tag=mytag&amp;linkCode=xm2&amp;camp=2025&amp;creative=165953&amp;creativeASIN=B004LAXG9C]]>
        </DetailPageURL>
        <URL>https://images-eu.ssl-images-amazon.com/images/I/412-16OaNFL._SL160_.jpg</URL>
        <Feature>Der neue "Alu-Teufel-Spezial" ist ein moderner Hochleistungs-Felgenreiniger. Die neue, säurefreie Rezeptur ermöglicht die problemlose Reinigung von Stahl- und Aluminiumfelgen sowie Radkappen. </Feature>
        <FormattedPrice>EUR 13,50</FormattedPrice>
        <Title>Tuga Chemie 76128 Felgenreiniger Alu-Teufel Spezial</Title>
    </Item>
</Items>

Why This Works

  • The <![CDATA[...]]> block acts as a "raw text" wrapper. The XML parser won’t try to interpret &amp; (or any other sequences) as XML markup, so it won’t throw that "invalid token" error.
  • When you read the DetailPageURL value in your Android code, it’ll still have the original &amp; strings—which will correctly resolve to & when you use the URL to open a web page or make a network request.

Avoid This Quick Fix (It’s Risky)

Some people suggest disabling XML validation in Android Studio to make the error go away, but I’d strongly advise against it. Turning off validation means you’ll miss real issues like missing tags or malformed XML later on. Save yourself the headache and use CDATA instead.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.11 08:57:12