3

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.
4

4 回答 4

7

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.

于 2009-10-13T11:42:21.500 回答
4

I realize this thread is fairly old but it is the first one that comes up in google when searching for this with jquery. The easiest way to do the search is with:

.find('[nodeName="content:encoded"]')

Hope that helps someone. I spent the last few hours trying to figure out a simple way to access those tags.

于 2011-10-11T19:07:23.713 回答
2

.find('[nodeName="content:encoded"]') it does works fine in Chrome and some older browsers.

于 2012-06-28T13:30:15.557 回答
0

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)

于 2009-10-13T12:17:16.967 回答