This is the full error:
System.XmlException: start tag unexpected character = (position: END_TAG seen ...<source> Bicycling</source><media:contenturl=... @1:688)
So from my understanding, this is not valid XML. I was having an issue with the session body and had to make the following change:
<rss xmlns:media="http:..." and had to add <rsstxlmns:media="https:..."
Now, I am not sure how to go about this with the = sign.
@isTest global class getRSSFeedMockCallout implements HttpCalloutMock { global HttpResponse respond(HttpRequest request) { String sessionBody = '<rsstxmlns:media="http://search.yahoo.com/mrss/"version="2.0">' + '<channel>'+ '<item>'+ '<title>Draymond Green Is a SoulCycle Devotee - Bicycling</title>'+ '<link>https://www.bicycling.com/news/a27024393/draymond-green-soulcycle/</link>'+ '<pubDate>Wed, 03 Apr 2019 12:00:00 GMT</pubDate>'+ '<description><a href="https://www.bicycling.com/news/a27024393/draymond-green-soulcycle/"target="_blank">Draymond Green Is a SoulCycle Devotee</a> <font color="#6f6f6f">Bicycling</font><p>If you take SoulCycle classes in the Bay Area, and you notice one extremely tall guy in the room, you may be looking at Golden State Warriors star Draymond ...</p></description>'+ '<source>Bicycling</source>'+ '<media:contenturl="https://lh5.googleusercontent.com/proxy/QvLCgDJMIqLENGFBUt1CCoUPO1XB6gJkGFPV5FuM0QKfyaG8WdhuHGtfcVaTzNzPAYyHo-arnqUBkWkZ8s7-p7WBUbKlfJ4xr0hl8hltQWsBCG0yDDh13Ul5qKrZgLvjQitRecmu=-w150-h150-c"medium="image"width="150"height="150"/>'+ '</item>'+ '</channel>'+ '</rss>'; HttpResponse res = new HttpResponse(); res.setHeader('Content-Type', 'text/xml'); res.setBody( sessionBody ); res.setStatusCode(200); return res; } }
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
There are few things wrong with the xml.
1) In Apex, the string starts and end with single quotes '
, thus you don’t need to escape "
2) You cannot use &
in XML, it makes XML invalid, you have to escape it.
will become &nbsp;
3) There is no tag as media:contenturl
in rss specification ,the tag is media:content
and having url
as an attribute. Seems like you missed a space in that.
Thus fixing all the above problem and formating the code, the code would be something like
String input = '<rss xmlns:media="http://search.yahoo.com/mrss/" version="2.0">' + '<channel>' + '<item>' + '<title>Draymond Green Is a SoulCycle Devotee - Bicycling</title>' + '<link>https://www.bicycling.com/news/a27024393/draymond-green-soulcycle/</link>' + '<pubDate>Wed, 03 Apr 2019 12:00:00 GMT</pubDate>' + '<description>' + '<a href="https://www.bicycling.com/news/a27024393/draymond-green-soulcycle/" rel="nofollow noreferrer noopener" target="_blank">Draymond Green Is a SoulCycle Devotee &nbsp;&nbsp; </a>' + '<font color="#6f6f6f">Bicycling</font>' + '<p>If you take SoulCycle classes in the Bay Area, and you notice one extremely tall guy in the room, you may be looking at Golden State Warriors star Draymond ...</p>' + '</description>' + '<source>Bicycling</source>' + '<media:content url ="https://lh5.googleusercontent.com/proxy/QvLCgDJMIqLENGFBUt1CCoUPO1XB6gJkGFPV5FuM0QKfyaG8WdhuHGtfcVaTzNzPAYyHo-arnqUBkWkZ8s7-p7WBUbKlfJ4xr0hl8hltQWsBCG0yDDh13Ul5qKrZgLvjQitRecmu=-w150-h150-c" medium="image" width="150" height="150"/>' + '</item>' + '</channel>' + '</rss>'; System.debug(input);
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0