I have this HTTP Post function in php which sends a form to a competition webservice, the response is an XML which gives further details if the entry was successful or not, how can I parse the results to capture the status field and give further feedback to the user?
Here is the code used:
<?php
$url = "...webserviceurl...";
$body = "userName=".$_POST["username"]."&password=".........;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form- urlencoded"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
//curl_setopt($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
curl_close ($ch);
print $result;
?>
Thanks
You can use the PHP DOMDocument library and DOMXpath libraries to run xpath queries on the XML:
If the response has an XML namespace that is unusual (like some APIs tend to do), you have to register the namespace and prefix all queries with it.