Parsing xml with namespaces


I've a little problem when I try to get a value inside a namespaced element. The XML document has the namespaces declarated but isn't possible to get that.
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:media="http://search.yahoo.com/mrss/" xmlns:atom="http://www.w3.org/2005/Atom">
<title>Any title</title>
<description>Any description</description>
<media:description type="html">Any description</media:description>
<media:title type="html">Any media title</media:title>
<media:content url="Any url" type="image/jpeg"></media:content>
<media:thumbnail url="Another url" width="100" height="46" />

The problem is that I can't get the media:thumbnail attributes nor anyone element with namespace.

I use this to parse and get the item element:
var xml_dom  = XMLDOM.parse( response );
if ( xml_dom ) {
var items_xml = xml_dom.evaluate('rss/channel/item');
for (var j=0; j<items_xml.length;j++){
var item = {
'title' : items_xml.item(j).evaluate('string(title)'),
'summary' : items_xml.item(j).evaluate('string(description)'),
'thumb' : ''//items_xml.item(j).evaluate('string(media:thumbnail@url)') // Can't get this values

Could someone help me?

I was thinking about use an external service to parse this xml as json as I read in other post of this forum, but i don't wanna to use an external service to do that.

Thanks and regards.

0 Replies

Recent Posts

in General - Yahoo! TV Widgets