views:

59

answers:

1

I'm currently making a widget to take and display items from a feed. I have this working for the most part, but for some reason the data within the tag within the item comes back as empty, but I get the data in the and tags no problem.

feed is and xmlhttp.responseXML object.

var items = feed.getElementsByTagName("item");

for (var i=0; i<10; i++){
    container = document.getElementById('list');
    new_element = document.createElement('li');
    title = items[i].getElementsByTagName("title")[0].firstChild.nodeValue;
    link = items[i].getElementsByTagName("link")[0].firstChild.nodeValue;
    alert(items[i].getElementsByTagName("description")[0].firstChild.nodeValue);
    new_element.innerHTML = "<a href=\""+link+"\">"+title+"</a> ";
    container.insertBefore(new_element, container.firstChild);
}

I have no idea why it wouldn't be working for the tag and would be for the other tags.

Here is an example of the rss feed its trying to parse:

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"&gt; 
  <channel> 
    <title>A title</title> 
    <link>http://linksomehwere&lt;/link&gt; 
    <description>The title of the feed</description> 
    <language>en-us</language> 
    <item> 
      <pubDate>Fri, 10 Jul 2009 11:34:49 -0500</pubDate> 
      <title>Awesome Title</title> 
      <link>http://link/to/thing&lt;/link&gt; 
      <guid>http://link/to/thing&lt;/guid&gt; 
      <description> 
       <![CDATA[
       <p>some html crap</p>
        blah blah balh
        ]]> </description> 
    </item> 
</channel>
</rss>
A: 

I'm not sure about javascript but many XML parsers create their own node for CDATA, so you might need to get the child of the CDATA node, which would mean your code isn't going deep enough to get the data inside the CDATA node.

danivovich