I am creating a widget that will be installed across different sites. The widget will parse an XML feed into JPlayer, because the widget will be installed across different sites AJAX is not an option, is there a way to parse XML with javascript without using AJAX. I am trying to stay away from PHP as well.
here is code in Simple XML, but I want to rewrite it in javascript.
$url = 'http://www.startalkradio.net/?page_id=354';
$rss = simplexml_load_file($url);
$items = $rss->channel->item;
<?php
$i = 0;
$data = array();
foreach ($items as $item) {
$data[] = array(
'title' => (string) $item->title,
'mp3' => (string) $item->enclosure['url'],
);
if (++$i == 3) break;
}
$jsdata = json_encode($data);
The following will parse and XML string into an XML document in all major browsers, including IE 6. Once you have that, you can use the usual DOM traversal methods/properties such as
childNodesandgetElementsByTagName()to get the nodes you want.Example usage: