0

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 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.