2010-09-07 4 views
0

Ok Je regardais ceci: Using jQuery to extract CDATA in XML for use as HTML contentSuppression de CDATA XML/RSS en utilisant jQuery

Mais il n'a pas aidé à ce que je fais. Je reçois un flux RSS/XML à partir d'une URL. J'ai un problème avec le CDATA dans la balise title et description. Voici l'élément d'alimentation:

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

Et voici le jQuery je jusqu'à présent:

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

Toutes les idées sur mon prochain arrêt pour enlever la balise CDATA donc je peux tirer le contenu sur?

Merci beaucoup!

Répondre

1

En fait, j'ai juste essayé quelque chose et cela a fonctionné. J'ai ajouté .text() au titre et la variable de lien comme si:

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

et cela a fonctionné très bien.

Merci!

+0

Yup. C'est tout :) Jquery pointe toujours vers les nœuds, donc vous devez accéder au texte si vous voulez le traiter! –

0

Peut-être qu'une mise à jour vers la dernière version de jquery pourrait résoudre votre problème, car cela fonctionne avec ma version.

Questions connexes