Jump to content

Reading XML response


lightlydone

Recommended Posts

Hi,

I'm posting an XML string using curl and trying to read response using DOMDocument but the returned array is empty.

Can anyone help with this?

 

curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, '1');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $leadXML);
$leadResult = curl_exec($ch);
curl_close($ch);


$xmlDoc = new DOMDocument();
$xmlDoc ->load($leadResult);
$x = $xmlDoc->getElementsByTagName("result");
$results = array();

foreach($x as $item){
$res = array();
if($item->childNodes->length)
{
	foreach($item->childNodes as $i){
		$res[$i->nodeName] = $i->nodeValue;
	}
}
$results[] = $res;
}

var_dump($results);

Link to comment
https://forums.phpfreaks.com/topic/239529-reading-xml-response/
Share on other sites

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.