views:

464

answers:

1

I have an Ajax request to an XML document. The XML document is an RSS feed. Here's my onSuccess for the request:

onSuccess: function(responseTree) {
 // process <item> elements
}

How do I enumerate <item> elements and retrieve the various child values?

A: 

The success-event returns an XML-object as well, if the content type of the called file is set to text/xml. However, beware of that this is not possible if you're calling a file on another server - it's not cross-domain. You can only use the Request-object to call files on the same domain.

Example code that enumerats through the item elements;

new Request({
 url: '/your-rss-parser.php',
 method: 'get',
 onSuccess: function(responseText, responseXML) {
  responseXML.getElements('item').each(function(item) {
   alert(item.getElement('title').get('text'));
  });
 }
}).send();
Björn