getting a parent node and its child, where the child has a certain text
我试图检索一个父节点,它是子节点,其中子节点具有特定文本。
这是我的HTML:
1 2 3 4 5 | <bod> <span>something</span> </body> |
我正在使用以下工具抓孩子:
1 | $the_child = $xpath->query('(//*[text()[contains(.,"something")]])[1]'); |
但是我又该如何捉住他的第一任父母?
获得项目后,只需获取其
纯XPath解决方案:
1 | (//*[*[contains(., 'something')]])[1] | (//*/*[contains(., 'something')])[1] |