XML 验证错误:EntityRef:期望';'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23422316/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 12:02:25  来源:igfitidea点击:

XML Validation error : EntityRef: expecting';'

xmlvalidationxml-validation

提问by user99322

<url>
  <loc>http://www.ezed.in/ezed/courseDemoIntroPage.do?courseId=COU10000000138003530&checkingCourseFrom=preLogin#.U2DcKvmSySo</loc>
</url>

error on line 102 at column 103: EntityRef: expecting';'

第 102 行第 103 列错误:EntityRef:期望';'

Not able to figure out what could be the problem.

无法弄清楚可能是什么问题。

回答by Adriano Repetti

Your URL must be escaped.

您的网址必须经过转义。

&character is used in XML to insert a character referencewith syntax &name;(note ;after name). Parser expects a ;but it can't find it (there are more available delimiters, this is just most common case).

&字符在 XML 中用于插入带有语法的字符引用&name;;名称后的注释)。解析器需要 a;但它找不到它(有更多可用的分隔符,这只是最常见的情况)。

Solution is then escaping (how it's done depends on language you use to generate that XML file) but final result must be something like this:

然后解决方案正在转义(如何完成取决于您用于生成该 XML 文件的语言)但最终结果必须是这样的:

<url>
  <loc>http://www.ezed.in/ezed/courseDemoIntroPage.do?courseId=COU10000000138003530&amp;checkingCourseFrom=preLogin#.U2DcKvmSySo</loc>
</url>

Note that plain &has been replaced with its escaped version &amp;. For further details see this simple article.

请注意,plain&已替换为其转义版本&amp;。有关更多详细信息,请参阅这篇简单的文章

Another possible solution (if you don't want/you can't escape) is to enclose URL inside a CDATA sectionlike this:

另一种可能的解决方案(如果您不想要/无法转义)是将 URL 包含在CDATA 部分中,如下所示:

<url>
  <loc><![CDATA[http://www.ezed.in/ezed/courseDemoIntroPage.do?courseId=COU10000000138003530&checkingCourseFrom=preLogin#.U2DcKvmSySo]]></loc>
</url>

回答by Vinod Patidar

Another way as below:

另一种方式如下:

Instead of "CDATA" we could use htmlspecialcharsPHPnative function for url node. it will work few of xml feed they don't want CDATAin xml output so this will be helpful for someone.

CDATA我们可以htmlspecialcharsPHP对 url 节点使用本机函数,而不是“ ” 。它将CDATA在 xml 输出中很少使用他们不想要的 xml 提要,因此这对某人有帮助。

Thanks

谢谢

回答by Bullsized

I stumbled on the same problem today, if you are building the links with PHP you can use this function:

我今天偶然发现了同样的问题,如果您使用 PHP 构建链接,则可以使用此功能:

htmlspecialchars();

It will format the desired string for you to HTML chars so you can insert it as a <loc>.

它会将所需的字符串格式化为 HTML 字符,以便您可以将其作为<loc>.

回答by Franco Michel Almeida Caixeta

simply replace '&' with '& a m p;' without the spaces, I put it here!

只需将 '&' 替换为 '& amp;' 没有空格,我把它放在这里!