0

我想知道我是否可以获得相邻节点的值

<item>
   <title>Cell Phone Plans That Make You Go Hmmm</title> 
   <link>http://www.articlegeek.com/computers/telecommunication_articles/10574-    cellphoneplanst.htm</link> 
    <description>Cell phone plans across the globe vary a great deal. Some say that cell phone  plans in the US are more costly. However, there are some advantages to the cell phone plans in the US which may balance the difference.</description> 
</item> 

这是我获取描述内容的查询,但我也想要与描述匹配的链接。

    $userIN = "cell";
    $nod2 = $xml->xpath 
  ("//description
              [text( 
                [contains
                 (translate(.,'ABCDEFGHJIKLMNOPQRSTUVWXYZ', 'abcdefghjiklmnopqrstuvwxyz'),
                   '".$userIN."')]]");
4

1 回答 1

0

我从另一个主题借用了这个答案:

SimpleXML 获取下一个/上一个节点

希望这可以帮助。

$xmlData = new SimpleXMLElement(file_get_contents("data.xml"));
$index = 0;
foreach($xmlData->row as $item) {
    if ($item->url == $_GET['id']) {
        // show photo
        $title = $item->title;

        $prev = $xmlData->row[$index-1];
        $next = $xmlData->row[$index+1];
    }
    $index++;
}
于 2013-05-01T23:33:35.480 回答