XML解析错误不能很好地形成。问题是在变量的内容,解决方法吗? [英] XML Parsing error not well formed. The problem is in the variable content, workaround?

查看:167
本文介绍了XML解析错误不能很好地形成。问题是在变量的内容,解决方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

工作的一个API,但我碰到的一个问题。

响应(以XML)的这种特定部分返回的URL。下面是我得到的错误:

  XML解析错误:没有很好地形成<item_to_page_url>http://cnn.com/.../?hpt=C2&replytocom=11119#respond</item_to_page_url>

首先,我添加了一个省略号缩短了长度这里查看论坛上的目的。现在,误差跟踪行的事,我不包括上面,指向第二等于=字符在该网址。

所以。我不能帮这个网址是表示XML响应起来。是否有某种解决办法吗?肯定有某种方式来告诉XML,它的内容,而不是&LT;标记&GT; 并使其忽略这个..

感谢

- 编辑下面的评论 -

 &LT; item_to_page_title&GT;&LT;![CDATA [最新新闻,实时比分和每日分析,从体育画报SI.com]&GT;&LT; / item_to_page_title&GT;

同样的错误和以前一样,不同的标签,不同的字符。


解决方案
肯定有某种方式来告诉XML,它的内容,而不是使之忽略这个..

确实存在。 CDATA标记将使XML解析器忽略的内容包含在其中。

<$p$p><$c$c><item_to_page_url><![CDATA[http://cnn.com/.../?hpt=C2&replytocom=11119#respond]]></item_to_page_url>

不过,如果你不想让解析器完全忽略的内容,你可以逃脱它。您收到的错误实际上不是由equals引起的签署,它是由amperstand造成前 - amperstands必须是XML转义为&放大器;放大器;

<$p$p><$c$c><item_to_page_url>http://cnn.com/.../?hpt=C2&amp;replytocom=11119#respond</item_to_page_url>

Working on an API but I've run into a problem.

This specific part of the response (in XML) returns a URL. Here's the error I'm getting:

XML Parsing Error: not well-formed

<item_to_page_url>http://cnn.com/.../?hpt=C2&replytocom=11119#respond</item_to_page_url>

First off, I added an ellipses to shorten the length of that for viewing purposes here on the forum. Now, The error tracker line thing, that I didn't include above, points to the second equals = character in that URL.

So. I can't help that this URL is showing up in the XML response. Is there some sort of workaround? Surely there's some way to tell XML that it's CONTENT, not <tags> and make it ignore this..

Thanks

--EDIT for comment below --

<item_to_page_title><![CDATA[Breaking news, real-time scores and daily analysis from Sports Illustrated  SI.com]]></item_to_page_title>

same error as before, different label, different character.

解决方案

Surely there's some way to tell XML that it's CONTENT, not and make it ignore this..

There is indeed. CDATA tags will make the XML parser ignore content contained within them.

<item_to_page_url><![CDATA[http://cnn.com/.../?hpt=C2&replytocom=11119#respond]]></item_to_page_url>

However, if you don't want the parser to completely ignore the content, you can just escape it. The error you're receiving is actually not caused by the equals sign, it is caused by the amperstand before it - amperstands must be escaped in xml as &amp;

<item_to_page_url>http://cnn.com/.../?hpt=C2&amp;replytocom=11119#respond</item_to_page_url>

这篇关于XML解析错误不能很好地形成。问题是在变量的内容,解决方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆