EK Posted March 10, 2011 Share Posted March 10, 2011 I have a form that I'm posting the contents to a 3rd party data management server via cURL. They return XML to let you know if the data was posted successfully or not. I'm trying to figure out how I can take that return XML and parse the data out of there. <?php extract($_POST); $url = 'https://www.*domain*.com/DataReceiver'; $fields = array( blah blah blah ); foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string,'&'); $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_POST,count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); $result = curl_exec($ch); Now my question is, when the data posts and the XML is returned, how do I capture that? When I don't use cURL and post directly using HTTP POST, I get the XML returned at the exact same address I post to. So to process the XML returned, is this code correct? $xml_feed_url = 'https://www.*domain*.com/DataReceiver'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $xml_feed_url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $xml = curl_exec($ch); curl_close($ch); I'm kind of at a loss on what to do from this point... Thanks to anyone who takes the time to read and can help! Link to comment https://forums.phpfreaks.com/topic/230181-question-about-return-xml-processing/ Share on other sites More sharing options...
requinix Posted March 10, 2011 Share Posted March 10, 2011 SimpleXML is a good place to start looking. Link to comment https://forums.phpfreaks.com/topic/230181-question-about-return-xml-processing/#findComment-1185455 Share on other sites More sharing options...
EK Posted March 10, 2011 Author Share Posted March 10, 2011 Thanks for the suggestion, but I'm getting errors that I can't include files from external domains when I try to use simplexml_load_file. Any other suggestions? Link to comment https://forums.phpfreaks.com/topic/230181-question-about-return-xml-processing/#findComment-1185461 Share on other sites More sharing options...
requinix Posted March 10, 2011 Share Posted March 10, 2011 You mean you're getting errors that mention allow_url_fopen? If so then you can't use SimpleXMLElement + a URL. Since cURL apparently works, use that to get the XML then feed it to SimpleXML. If not then what error messages are you getting? Link to comment https://forums.phpfreaks.com/topic/230181-question-about-return-xml-processing/#findComment-1185466 Share on other sites More sharing options...
EK Posted March 10, 2011 Author Share Posted March 10, 2011 OK got it working now with simplexml_load_file Not sure how to parse the resulting code though. I'm getting something like: [Variable] => Value [Variable] => Value [Variable] => Value [Variable] => Value Thanks for your help. Link to comment https://forums.phpfreaks.com/topic/230181-question-about-return-xml-processing/#findComment-1185478 Share on other sites More sharing options...
salathe Posted March 10, 2011 Share Posted March 10, 2011 Have a look through the basic SimpleXML examples, and if you're having trouble post a sample of the XML itself for us to help you with. Link to comment https://forums.phpfreaks.com/topic/230181-question-about-return-xml-processing/#findComment-1185482 Share on other sites More sharing options...
EK Posted March 10, 2011 Author Share Posted March 10, 2011 This is in my PHP code: $xml = simplexml_load_file('https://www.....com/...Receiver'); print_r($xml); My output looks like this: SimpleXMLElement Object ( [isValidPost] => false [ResponseType] => LeadType_ID_Missing [ResponseDetails] => Lead Type ID (LID) is required, please refer to the post documentation [LeadIdentifier] => 0 [VendorAccountAssigned] => 0 [PendingQCReview] => false [Price] => 0 ) My goal is to get variables that I can pass elsewhere. For example I want to get [ResponseType] out so I can pass it in a URL string for example. Ex of how I'd like to use the code: header ("Location: nextpage.php?[ResponseType]=$ResponseType") Link to comment https://forums.phpfreaks.com/topic/230181-question-about-return-xml-processing/#findComment-1185486 Share on other sites More sharing options...
salathe Posted March 10, 2011 Share Posted March 10, 2011 The examples on the page that I linked to didn't help at all? Link to comment https://forums.phpfreaks.com/topic/230181-question-about-return-xml-processing/#findComment-1185510 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.