XPath 查找具有特定文本的特定节点 [英] XPath finding certain node with certain text

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

问题描述

所以我有一个类似的问题:

So I had a question regarding something similar to that at:

获取一个父节点及其子节点,其中子节点具有特定文本

但是情况发生了变化,我发现我的上述想法有些问题.我现在正在尝试查找具有特定文本的节点,因为当我使用 29 时,它似乎还会找到包含 2999 或其他任何包含 29 的节点.

But the situation change and I find some problems with my above idea. I am now trying to find a node with specific text because it seems when I use 29 it will also find nodes that has 2999 or anything else that has 29 in it.

所以我的问题是我该如何转向:

So my question is how can I turn :

$myvar = $xpath->query('(///*[text()[contains(., "something")]])');

所以它会寻找带有特定文本的节点.不适用于具有"特定文本的节点.

so it will look for node with certain text. not for a node that "has" certain text.

推荐答案

只需使用 //*[text() = "29"] 而不是 contains().

Just use //*[text() = "29"] instead of contains().

这篇关于XPath 查找具有特定文本的特定节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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