php simplexml xpath问题
嘿,我是 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 />";
}
所以我的问题在代码中评论,当我有 title 元素值时检索 filmid 的 xpath 语法是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)