How to use AND operator in XPath?

后端 未结 2 1960
被撕碎了的回忆
被撕碎了的回忆 2021-01-13 15:24

XML is like

 
   value1
   value2
 

I want to write XPath to find id of <

2条回答
  •  再見小時候
    2021-01-13 16:06

    contains function can do it.

    $nodes = $xpath->query("//b[contains(., 'value1')] | //b[contains(., 'value2')]");
    

    And then, to get the parent id

    $parent_id = $nodes->item(0)->parentNode->getAttribute("id");
    

    A demo (with HTML) here.

提交回复
热议问题