开发者

php simplexml xpath question

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_nam开发者_如何学JAVAe 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜