Jump to content

Question about return XML processing


EK

Recommended Posts

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

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?

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")

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.