繁体   English   中英

在php4中解析xml

[英]xml parsing in php4

我知道这可能太多了,但我一直在阅读有关xml解析的内容,我只是不明白! 我没有意识到我的客户端有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');

我只是难过。 我只使用过这种格式来读取xml文档。 任何人都可以将其转换为php4上的工作吗? 我再次知道这有很多要问,但任何帮助都会非常感激。 先感谢您。

你应该记下你的客户PHP 4已经没有任何支撑可言 ,因为8月8日 ,2008年

也就是说,阅读这个问题已经解决了你的问题。

(来自参考答案)

$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),那么应该承担相应的费用; 维护遗留代码通常需要更多努力。

暂无
暂无

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

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