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
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?

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.