0

Ok So I looked at this: 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</link>
   <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</guid>
   <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!

2 Answers 2

1

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!

Sign up to request clarification or add additional context in comments.

1 Comment

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

Maybe an update to the latest jquery version might solve your problem, because this works with my version.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.