节点名称中带有冒号的 XML 节点的 XPath 查询 [英] XPath query for XML node with colon in node name

查看:37
本文介绍了节点名称中带有冒号的 XML 节点的 XPath 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪个 XPath 查询会选择以下 XML 中的 节点?

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>

XML 来自这个 RSS 提要.>

The XML came from this RSS feed.

推荐答案

您需要了解名称空间以及如何在 XPath 引擎中定义/注册名称空间,以便您可以使用关联的该注册命名空间中名称的前缀.xpath 标签中有很多问题,询问如何使用命名空间中的名称 - 有很好的答案.搜索它们.

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']

这篇关于节点名称中带有冒号的 XML 节点的 XPath 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆