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.
The colons indicate that those elements are in the ns1 namespace. This is needed when you are using multiple schemas. Assuming the document only uses ns1, it is essentially equivalent to not having any "ns1:" in those tags.
In XPath, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document nodes. XML documents are treated as trees of nodes. The topmost element of the tree is called the root element.
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']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With