XPath filtering on attribute with namespace

Viewed 19493

I need to create XPath expression to filter based on attribute that is in given namespace. Example XML is:

<feed xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/'
  xmlns:yt='http://gdata.youtube.com/schemas/2007'> ...
 <entry>
  <media:group>
   <media:thumbnail url='http://i.ytimg.com/1.jpg' yt:name='default'/>
   <media:thumbnail url='http://i.ytimg.com/2.jpg' yt:name='hqdefault'/>
   <media:thumbnail url='http://i.ytimg.com/3.jpg' yt:name='start'/>
   <media:thumbnail url='http://i.ytimg.com/4.jpg' yt:name='middle'/>
  </media:group>
 </entry>

And I need to get the url of the node with attribute yt:name set to 'hqdefault'.

I tried with XPath expression

'./media:group/media:thumbnail[@yt:name='hqdefault']/@url'

but it seems that specifying namespaced attribute with yt:name does not work. I get an empty DOMNodeList upon making a query.

I am accessing XML in php, so I registered yt namespace:

registerNamespace( 'yt', 'http://gdata.youtube.com/schemas/2007' );

Thnx in advance

3 Answers
Related