Удаление CDATA из XML / RSS-канала с помощью jQuery - PullRequest
0 голосов
/ 07 сентября 2010

Хорошо. Итак, я посмотрел на это: Использование jQuery для извлечения CDATA в XML для использования в качестве содержимого HTML

Но это не помогло с тем, что я делаю.Я получаю RSS / XML-канал от URL.У меня проблема с CDATA в теге заголовка и описания.Вот элемент фида:

  <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>

А вот jQuery, который у меня есть на данный момент:

   $.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');

Любые идеи по моей следующей остановке для удаления тега CDATA, чтобы я мог просто извлечь содержимоеout?

Большое спасибо!

Ответы [ 2 ]

1 голос
/ 07 сентября 2010

На самом деле я просто попробовал что-то, и это сработало.Я добавил .text () в заголовок и переменную ссылки следующим образом:

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

, и все заработало.

Спасибо!

0 голосов
/ 22 ноября 2010

Возможно, обновление вашей последней версии jquery может решить вашу проблему, потому что это работает с моей версией.

...