xpath simplexml标记查询以及如何获取节点值

问题描述:

我有我的xpath查询使用simpleXML,我想用它来获取标记标题,描述和链接的节点值。但我不知道如何输出它们,比如只输出标题内容。xpath simplexml标记查询以及如何获取节点值

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

function xmlXpath() 
{ 
    $xml = xmlParse(); 

    $userIN = "cell"; 
    $nodesT = $xml->xpath(" 
     //* 
     [ 
      text() 
      [ 
       contains(
        translate(.,'ABCDEFGHJIKLMNOPQRSTUVWXYZ', 
           'abcdefghjiklmnopqrstuvwxyz'), 
        '".$userIN."' 
       ) 
      ] 
     ] 
    "); 
    return $nodesT; 
} 
+0

请发表您的XML代码在你的问题,而不是链接。 – michi 2013-05-01 21:41:35

编辑:考虑您的XPath,做到:

foreach ($nodesT as $nodeT) echo "$nodeT <br />"; 

看到它的工作:http://codepad.viper-7.com/WKDfvJ

+0

对不起,我不知道如何显示xml,所以我将它链接到它所在的位置。 – DOWmad 2013-05-01 21:44:49

+0

@DOWmad:简单地将它复制到你的问题中,并像代码一样缩进它。 – michi 2013-05-01 21:46:09

+0

我试过你的上面的代码,但它不会产生任何东西 – DOWmad 2013-05-01 21:49:44