2013-05-01 125 views
0

我有我的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

回答

1

編輯:考慮您的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