TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Xpath query (http://www.talkphp.com/general/5884-xpath-query.html)

OvinBovin 06-12-2011 12:42 AM

Xpath query
 
Hi all,

I am looking for a function that finds a string from a RSS feed and retrieve the whole content of the matched nodes values.

I've made unsuccessfull tests using fn:matches function.

Here is my PHP code ;

$document = new DOMDocument();
$document->preserveWhiteSpace = FALSE;
$document->load("soccer-rss.xml");
$xpath = new DOMXPath($document);
$string="Liga";
$markup="title";
$query = '/rss/channel/item/' . $markup .'[fn:matches(".","' . $string .'")]';
$results = $xpath->query($query);
...

In this example I wanted to retrieve titles containing the word "Liga" from RSS titles.

When submitting query /rss/channel/item/title[fn:matches(".","Liga")] my code displays all titles, even those not containing the word "Liga".

Does anyone have any idea to solve this ?

OvinBovin 06-12-2011 02:29 PM

Xpath query solution
 
Hi all,

I've found a solution with contains function to query by an element's enclosed text :

$query="/rss/channel/item/title[contains(.,'Liga')]";

I can get out now, I'm free :-)

Happy Sunday,

Wildhoney 06-21-2011 06:17 AM

Aha! Somebody else who loves XPath as me, I suppose :-) Yes, the contains method will serve you well there.


All times are GMT. The time now is 12:39 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0