2009-08-19 37 views
0
<?php 
 

error_reporting(E_ALL); 

$url = 'saved_report.xml'; 


define('XML_HEADER', '*RWRESPONSE*RESPONSE*DATA*HEADER*COLUMN'); 
define('XML_ROW', '*RWRESPONSE*RESPONSE*DATA*ROW*COLUMN'); 

$headers = array(); 
$rows = array(); 

function startTag($parser, $data) { 
    global $current_tag; 
    $current_tag .= "*$data"; 
} 

function endTag($parser, $data) { 
    global $current_tag; 
    $tag_key = strrpos($current_tag, '*'); 
    $current_tag = substr($current_tag, 0, $tag_key); 
} 

function contents($parser, $data) { 
    global $current_tag, $headers, $rows; 
    switch($current_tag) { 
     case XML_HEADER: 
      array_push($headers, $data); 
      break; 
     case XML_ROW: 
      array_push($rows, $data); 
      break; 
    } 
} 




// fetch the report 
$curl_object = curl_init(); 
curl_setopt($curl_object, CURLOPT_URL, $url); 
curl_setopt($curl_object, CURLOPT_HEADER, 0); 
curl_setopt($curl_object, CURLOPT_RETURNTRANSFER, 1); 

curl_setopt($curl_object, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($curl_object, CURLOPT_SSL_VERIFYHOST, 0); 

$result = curl_exec($curl_object); 
$error = curl_error($curl_object); 
$info = curl_getinfo($curl_object); 
curl_close($curl_object); 

if ($error) { 
    die("An error occured while fetching the report\n"); 
} 


// process the report 
$xml_parser = xml_parser_create(); 
xml_set_element_handler($xml_parser, "startTag", "endTag"); 
xml_set_character_data_handler($xml_parser, "contents"); 

if(!(xml_parse($xml_parser, $result))){ 
    die("Error on line " . xml_get_current_line_number($xml_parser)); 
} 
xml_parser_free($xml_parser); 

for($i = 0; $i \n"; 
} 

echo '
'; echo "$headers[3]: $rows[3]
\n"; echo "$headers[4]: $rows[4]
\n"; ?>

運行此腳本時,我收到一個錯誤捲曲錯誤無法解析主機:saved_report.xml;請求類型的數據記錄「

」無法解析主機:saved_report.xml;請鍵入」

的沒有數據記錄我不能夠解決這個

回答

1

您需要指定文件的完整路徑,如:

$url = 'http://example.com/saved_report.xml'; 

如嫋嫋不與相關工作網址