views:

50

answers:

2

I have a xml file

<events date="30/08/2010">
<event>
<title>here</title>
<description>
This is first Event This is first Event This is first Event This is first Event This is first Event This is first Event This is first Event This is first Event This is first Event This is first Event
</description>
</event>
</events>
<events date="31/08/2010">
<event>
<title>Second Event </title>
<description>
Second Event Second Event Second Event Second Event Second Event Second Event Second Event Second Event Second Event Second Event
</description>
</event>
</events>

from this xml how i can select the event with title Second Event using xquery.I used

$nodes = $xml->xpath('//xml/events/event[@title="'.$title.'"]');

but it is not working, can anybody help me

+2  A: 

You don't have a node called "xml" so your query should not start "xml". Title is not an attribute, so remove the "@". This (untested) ought to work:

//events/event[title="'.$title.'"]'

and return a node list.

Andrew Walker
My xml is start with xml thats y i used .I tried this one then also it is not working
THOmas
@THOmas the above works fine for me with the XML you show in your question. Just make sure you use `Second Event ` with the trailing space to find the node or switch to `/events/event[normalize-space(title)="Second Event"]` or - better - `/events/event[contains(title, "Second Event")]`
Gordon
Thanks /events/event[title="'.$title.'"]' It will work
THOmas
A: 
$nodes = $xml->xpath('//xml/events/event[title="'.$title.'"]');
THOmas