views:

39

answers:

1

Ok So I looked at this: http://stackoverflow.com/questions/2308889/using-jquery-to-extract-cdata-in-xml-for-use-as-html-content

But it didn't help with what I'm doing. I'm getting an rss/xml feed from a url. I'm having an issue with the CDATA in the title and description tag. Here's the feed item:

  <item>
   <title><![CDATA[Impact South Africa (Girls)]]></title>
   <link>http://www.thriveafricastore.com/products.php?product=Impact-South-Africa-%28Girls%29&lt;/link&gt;
   <pubDate>Mon, 29 Mar 2010 19:02:26 +0000</pubDate>
   <guid isPermaLink="false">http://www.thriveafricastore.com/products.php?product=Impact-South-Africa-%28Girls%29&lt;/guid&gt;
   <description><![CDATA[<div style='float: right; padding: 10px;'><a href="http://www.thriveafricastore.com/products.php?product=Impact-South-Africa-%28Girls%29"  ><img src="http://www.thriveafricastore.com/product_images/t/266/girls__27047_thumb.jpg" alt="" /></a></div><p><strong>You can help us impact South Africa. Do something!<br /></strong></p>
<p>Your basic jersey tee, only better! Made just for women, it contours to your shape and always looks flattering and chic even with a simple pair of jeans. This is one t-shirt you'll want to stock pile. Pre-shrunk 1..<p><strong>Price: <span class="SalePrice">$10.00</span></strong> </p>]]></description>
   <content:encoded><![CDATA[<div style='float: right; padding: 10px;'><a href="http://www.thriveafricastore.com/products.php?product=Impact-South-Africa-%28Girls%29"  ><img src="http://www.thriveafricastore.com/product_images/t/266/girls__27047_thumb.jpg" alt="" /></a></div><p><strong>You can help us impact South Africa. Do something!<br /></strong></p>
<p>Your basic jersey tee, only better! Made just for women, it contours to your shape and always looks flattering and chic even with a simple pair of jeans. This is one t-shirt you'll want to stock pile. Pre-shrunk 1..<p><strong>Price: <span class="SalePrice">$10.00</span></strong> </p>]]></content:encoded>
  </item>

And here's the jQuery I have so far:

   $.get('http://www.thriveafricastore.com/rss.php?type=xml', {}, function(d) {

     $('body').append('New Thrive Store Items'); 
     $('body').append('<div>');

    $('item', d).each(function() {

     var $item = $(this);
     var title = $item.find('title');
     var description = $item.find('description').text();
     var link = $item.find('link');
     var html = '<h3><a href="' + link + '">' + title + '</a></h3>';

     $('div').append($(html));

    });
   }, 'xml');

Any ideas on my next stop to removing the CDATA tag so I can just pull the content out?

Thanks so much!

A: 

Actually I just tried something and it worked. I added .text() to the title and the link variable like so:

            var title = $item.find('title').text();
            var description = $item.find('description').text();
            var link = $item.find('link').text();

and it worked just fine.

Thanks!

Marc
Yup. That's it :) Jquery always points to the nodes, so you need to access the text if you want to deal with it!
Julien Genestoux