简体   繁体   English

在php4中解析xml

[英]xml parsing in php4

I know that this might be way too much to ask, but I have been reading about xml parsing and I just do not understand it! 我知道这可能太多了,但我一直在阅读有关xml解析的内容,我只是不明白! I did not realize that my client had PHP 4 until I was done programming (a lesson well learned), but I need this to work in php4: 我没有意识到我的客户端有PHP 4,直到我完成编程(这是一个很好的经验教训),但我需要这个在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');

I am simply stumped. 我只是难过。 I have only ever used this format to read an xml document. 我只使用过这种格式来读取xml文档。 Can anyone out there transform this to work on php4?? 任何人都可以将其转换为php4上的工作吗? Again I know that this is a lot to ask, but any help would be so greatly appreciated. 我再次知道这有很多要问,但任何帮助都会非常感激。 Thank you in advance. 先感谢您。

You should make a note to your client that PHP 4 has not had any support at all since August 8 th , 2008 ! 你应该记下你的客户PHP 4已经没有任何支撑可言 ,因为8月8日 ,2008年

That said, read this question which already address your problem. 也就是说,阅读这个问题已经解决了你的问题。

(from referenced answer) (来自参考答案)

$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);

If your client really want to stick with unsupported PHP versions (or can't migrate to PHP 5), it is something that he should assume the cost for; 如果您的客户真的想要坚持使用不受支持的PHP版本(或者无法迁移到PHP 5),那么应该承担相应的费用; maintaining legacy code usually requires more efforts. 维护遗留代码通常需要更多努力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM