2015-10-26 87 views
0

即時通訊嘗試使用PHP xpath從XML文件中過濾掉一些信息,不知何故,響應似乎總是空的。有沒有人有一個想法可能會導致這種情況?PHP xpath不會返回數據


XML例子:

<account> 
    <a>Information1</a> 
    <b>Information2</b> 
    <c>Informatio3</c> 
</account> 

我的實際代碼:

public static function user_cache($username) { 
     $xml = @file_get_contents('xmlfile'); 
     $xml = @simplexml_load_string($xml); 
     if ($xml) { 
     $results = array(
      "userid" => $xml->xpath('a') 
     ); 
     } 
     else { 
     $results['message'] = 'Unable to get data.'; 
     } 
     return $results; 
    } 

{ 
    "userid": [] 
} 

回答