Izmoto
Izmoto

Reputation: 1959

XPath query for XML node with colon in node name

What XPath query will select the <media:thumbnail /> node in the following XML?

<item>
  <title>Sublime Federer crushes Wawrinka</title>
  <description>Defending champion Roger Federer cruises past Stanislas Wawrinka 6-1 6-3 6-3 to take his place in the Australian Open semi-finals.</description>
  <link>http://news.bbc.co.uk/go/rss/-/sport2/hi/tennis/9372592.stm</link>
  <guid isPermaLink="false">http://news.bbc.co.uk/sport1/hi/tennis/9372592.stm</guid>
  <pubDate>Tue, 25 Jan 2011 04:21:23 GMT</pubDate>
  <category>Tennis</category>
  <media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/50933000/jpg/_50933894_011104979-1.jpg"/>
</item>

The XML came from this RSS feed.

Upvotes: 40

Views: 35583

Answers (3)

Dushyanth Kandiah
Dushyanth Kandiah

Reputation: 716

If you're looping an XmlNodeList array just use *[local-name()='thumbnail']

Upvotes: 1

Skystrider
Skystrider

Reputation: 399

What worked for me is:

/item/*[local-name()='thumbnail']

Upvotes: 8

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243529

You need to learn about namespaces and how to define/register a namespace in your XPath engine so that you can then use the associated prefix for names in that registered namespace. There are plenty of questions in the xpath tag asking how to use names that are in a namespace -- with good answers. Search for them.

A very rough answer (ignoring namespaces at all) is:

//*[name()='media:thumbnail']

Upvotes: 61

Related Questions