2

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 <rss\txlmns: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 = '<rss\txmlns: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>&nbsp;&nbsp;<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;
  }   
}
4

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. &nbsp; will become &amp;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/" target="_blank">Draymond Green Is a SoulCycle Devotee &amp;nbsp;&amp;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);
  • You are the man! Works perfectly now. – Matthew Metros Apr 8 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.