php simplexml xpath问题

时间:2010-06-01 08:43:27

标签: php xpath simplexml

嘿,我是xPath的新手,时间不利于我,我现在没有时间去了解它,所以我希望你们能帮助我! :)

这是我的xml格式:

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

这是一些php代码,将文档加载到simplexml对象中,然后进行一些搜索($ movie_name变量是作为函数参数传递的字符串):

$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 />";
    }

所以我的问题在于代码注释,当我有titel元素值时,检索filmid的xpath语法是什么?

1 个答案:

答案 0 :(得分:1)

  

//性标题[含有(·, '鸟')] /祖先:: * / filmid