获取父节点及其子节点,其中的子节点具有特定的文本 [英] getting a parent node and its child, where the child has a certain text

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

问题描述



这是我的html:

 < bod> 
< div>
< span>东西< / span>
< / div>
< / body>

我使用以下内容来抓住孩子:


$ b $ ('([* [text()[contains(。,something)]])[1]');} $ the_child = $ xpath->

但是我怎么也抓住他的第一个父母?

解决方案

获得该项目后,只需获取其 - > parentNode 属性。


I am trying to retrieve a parent node and it's child, where the child has a certain text.

this is my html:

<bod>
    <div>
         <span>something</span>
    </div>
</body>

i am using the following to catch the child :

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

but how do i also catch his first parent ?

解决方案

Once you have the item, just get its ->parentNode property.

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

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