views:

18

answers:

1

Hey, I'm very newbie to xPath and time is against me, I don't have the time right now to learn a lot about it, so I hope you guys can help me with this! :)

Here is my xml format:

<Filme>
 <Film>
  <filmid>13497</filmid>
  <originaltitel>Bird</originaltitel>
  <originaluntertitel></originaluntertitel>
  <titel>Bird (OmU)</titel>
  <untertitel></untertitel>
  <filmstart>0000-00-00</filmstart>
  <fsk>12</fsk>
 </Film>
</Filme>

Here is some php code, loading the document into a simplexml object, and do some search (the $movie_name variable is a string passed as an argument to the function):

$xml = simplexml_load_file("/somePath/Filme.xml");

//will find all the titles that contains the string $movie_name
foreach( $xml->xpath("//titel[contains(.,'$movie_name')]") as $title){

        //need to find the filmid corresponding to this film title
        //$id = ?????
        $res .= $title."<input type='checkbox' name='movies' value='$id' ><br />";
    }

So my question is in the code comments, what is the xpath syntax to retrieve the filmid when I have the titel element value?

+1  A: 

//titel[contains(.,'Bird')]/ancestor::*/filmid

nuqqsa
Thanks, that was very helpful.I actually modified this to: //titel[.='$title']/ancestor::*/filmid in order to get the id for this specific title, and not the id that contains this title.
Piero