views:

517

answers:

2

I am using jQuery to parse an RSS feed. Within each <item> is a namespaced element like <content:encoded> I want to select. How do I select it in jQuery?

$(xml).find('item') works but $(xml).find('item content') does not.
+1  A: 

Are you loading the xml via Ajax? Then, make sure that the server sets the content type as 'text/xml' and not 'text/html'.

Also make sure that the tag name of the element you want is indeed content and not something else (like content:encoded). In that case try:

.find('item content\\:encoded')?

Special characters like : need to be escaped in jQuery selectors.

kgiannakakis
First thing I checked. It's feed.xml, so reading it as an XML file.The issue is that the tag name is content:encoded.
Corey Maass
Try escaping the : then.
kgiannakakis
A: 

This is what I got from a search

jQuery selectors are not namespace-aware, so they only use getElementsByTagName (rather than getElementsByTagNameNS) to retrieve elements by their nodeName attribute (rather than by localName and namespaceURI).

Looks like you need to do it in regular js by using the document.getElementsByTagNameNS(namespace, tagname)

Samuel