2012-10-13 35 views
0

我知道這可能太多問,但我一直在閱讀有關XML解析,我只是不明白它!我不知道,我的客戶有PHP 4,直到我做節目(一個很好的教訓教訓),但我需要這在PHP4工作:xml解析php4

$post_string= 'type=xml&cid=55505&minorRev=14&apiKey=4sr8d8bsn75tpcuja6ypx5g3&locale='.$userLocale.'&currencyCode='.$userCurr.'&customerIpAddress='.$userIp.'&customerUserAgent='.$userAgent.'&xml=<HotelListRequest><destinationId>7EEF0188-E4DC-4B45-B4A7-57E3DF950E1F</destinationId><supplierCacheTolerance>MED_ENHANCED</supplierCacheTolerance><numberOfResults>200</numberOfResults></HotelListRequest>'; 
//Relative path to the file with $_POST parsing 
$path = "http://api.ean.com/ean-services/rs/hotel/v3/list"; 
$ch = curl_init($path); 
$fp = fopen('xml/data.xml','w'); 
//Send the data to the file 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/xml')); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_FILE, $fp); 
$val = curl_exec($ch); 
curl_close($ch);//Close curl session 
fclose($fp); //Close file overwrite 
$data = simplexml_load_file('xml/data.xml'); 

我只是難倒。我只用過這種格式來讀取一個XML文檔。任何人都可以改變這個在php4上工作?我再次知道,這是很多要問,但任何幫助將非常感激。先謝謝你。

+0

只是好奇..爲什麼PHP 4? – Baba

+3

您的客戶端應該確實遷移到PHP 5. PHP 4不再被維護,甚至沒有安全更新。如果是託管公司,他們拒絕更新,請離開。 (有些情況下,因爲舊軟件需要PHP 4,但除非有完全迫切的原因,否則使用PHP 4今天是不行的。) –

+0

認真? PHP4?這些天我不得不與5.2一起工作。我建議你把你的客戶指向這個頁面:http://php.net/releases/index.php。 PHP4已經過時並且危險地不安全。但更重要的是,考慮到它已停產多久,運行PHP4的操作系統也可能是危險的不安全。只有通過使這種系統在線,您的客戶纔有被黑客入侵的風險。你的問題是他們可能頭腦發熱:通過接受該項目,如果他們被黑客入侵,你很可能會受到指責。我的建議:跑掉 – Spudley

回答

2

您應該記下您的客戶PHP 4沒有任何支持因爲August 8th, 2008

這就是說,讀了this這個問題已經解決了你的問題。

(從參考答案)

$xml = ...; // Get your XML data 
$xml_parser = xml_parser_create(); 

// _start_element and _end_element are two functions that determine what 
// to do when opening and closing tags are found 
xml_set_element_handler($xml_parser, "_start_element", "_end_element"); 

// How to handle each char (stripping whitespace if needs be, etc 
xml_set_character_data_handler($xml_parser, "_character_data"); 

xml_parse($xml_parser, $xml); 

如果您的客戶端真的想堅持不支持PHP版本(或不能移植到PHP 5),它是什麼,他應該承擔成本維護遺留代碼通常需要更多努力。

+0

驗收表明這是重複的材料,那麼刪除它可能是非常值得的。 – hakre