开发者

XML Parsing error not well formed. The problem is in the variable content, workaround?

开发者 https://www.devze.com 2023-01-07 21:35 出处:网络
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:

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号