Associate text with XPATH syntax

Exmple feed: view-source: http://rss.packetstormsecurity.org/files/tags/exploit/

I only want to return the xml sections, where the parent node header has the corresponding text in it, in this example the text to match is "site".

//get feed with curl $doc = new SimpleXmlElement($xml, LIBXML_NOCDATA); //$result = $doc->xpath('//title'); //this works returns all the <title>'s $result = $doc->xpath('//title[site]'); //doesn't work $result = $doc->xpath('//title[text()="site"]'); //doesn't work $result = $doc->xpath('//title[contains(site)]'); //doesn't work $result = $doc->xpath('//title[contains(text(),'Site')]'); //doesn't work foreach ($result as $title) echo "$title<br />" 
+6
xml php xpath simplexml
source share
1 answer

The call you need, I think, is:

 $result = $xpath->query('//title[contains(.,"Site")]'); 

Please note that this is case sensitive.

Note that the contains XPath function takes two arguments: a haystack and a needle. In this case, we use the current text value of the node as a haystack, which is indicated by a period ( . ).

+19
source share

All Articles