views:

17

answers:

1

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&amp;replytocom=11119#respond&lt;/item_to_page_url&gt;

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.

+1  A: 
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]]&gt;&lt;/item_to_page_url&gt;

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;amp;replytocom=11119#respond&lt;/item_to_page_url&gt;
lucideer
thankss! works beautifully. Now I've got another problem. Same error, but it's under a different <> tag/label. I tried the CDATA tags, but i'm still getting this error. This time XML is saying it's caused by a character in the content... I really need to foolproof this api. Is there a different tag I should use?
Dylan Taylor
The line you've posted in your edit above is perfectly valid XML - nothing wrong with it. Perhaps it's an encoding issue of some sort - are you using UTF-8? What kind of app is this?
lucideer
No the char set isn't set. The page this is runnning on is a PHP page, running off MAMP. Umm it just grabs data from MySQL and puts puts it in XML, then here we are. Let me try encoding the page in utf-8...
Dylan Taylor
set it to utf-8.. same damn problem. this is killing me. i'll just start a new thread. thanks for you help tho.
Dylan Taylor