按属性名称选择 xml 节点,忽略该属性的命名空间 [英] Select xml node by attribute name ignoring namespace of that attribute

查看:34
本文介绍了按属性名称选择 xml 节点,忽略该属性的命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的节点:

<meta name="og:description" content="Here's the content" />

如果名称是描述",无论它是否在命名空间中,我都希望能够选择此元素.如果元标记的名称是og:description"、description"、blah:description"等,我需要能够选择它.

I want to be able to select this element if the name is "description" whether it's in a namespace or not. I need to be able to select the meta tag if it's name is "og:description", "description", "blah:description", etc.

我已经看到了 xpath 的资源,这些资源展示了如何在命名空间内进行选择,但并非不考虑命名空间.

I've seen resources for xpath that show how to select within a namespace, but not irrespective of a namespace.

推荐答案

使用 XPath 2 你可以:

Using XPath 2 you could do:

 /meta[ends-with(@name, 'description')]

对于 XPath 1,我们需要:

For XPath 1 we need:

 /meta['description' = substring(@name, string-length(@name) - string-length('description') + 1)]

这篇关于按属性名称选择 xml 节点,忽略该属性的命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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