0

I have a problem, I'm trying to get data from http://www.acquaintcrm.co.uk/propertyfunctions/propertysearch.asmx?op=GetDataV8

I have made the request and output the data to a file, properties.xml

The file gets filled with data, but I just dont know how to use that data, I would like to convert the xml data into an array, but I honestly don't know where to start.

My code

$xml_data = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <GetDataV8 xmlns="http://www.AcquaintCRM.co.uk/propertyfunctions/">
          <strSitePrefix>STDZ</strSitePrefix>
          <intSiteID>-1</intSiteID>
          <intPropertyID>0</intPropertyID>
          <intPropertyDevelopmentID>0</intPropertyDevelopmentID>
          <bytBedrooms>0</bytBedrooms>
          <decMinPrice>0</decMinPrice>
          <decMaxPrice>0</decMaxPrice>
          <bytTenure>1</bytTenure>
          <intCommercial>-1</intCommercial>
          <bytPropertyAge>0</bytPropertyAge>
          <intRentalTerms>0</intRentalTerms>
          <bytFeaturedCount>0</bytFeaturedCount>
          <strAreas></strAreas>
          <strTypes></strTypes>
          <bytSortOrder>0</bytSortOrder>
          <bytUseCDataTags>0</bytUseCDataTags>
        </GetDataV8>
      </soap:Body>
    </soap:Envelope>
';

$url = "http://www.acquaintcrm.co.uk/propertyfunctions/propertysearch.asmx?op=GetDataV8";

$headers  = array(
  "POST * HTTP/1.1",
  "Content-type: text/xml;charset=\"utf-8\"",
  "Accept: text/xml",
  "Cache-Control: no-cache",
  "Pragma: no-cache",
  "Content-length: ".strlen($xml_data),
  "SOAPAction: http://www.AcquaintCRM.co.uk/propertyfunctions/GetDataV8",
);

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);

$response = curl_exec($ch);

if (curl_errno($ch))
{
    echo 'Error: ';
    echo curl_error($ch);
}
else
{
  curl_close($ch);

  $xml = file_put_contents('properties.xml', $response);

  $xml = simplexml_load_file('properties.xml');

  print_r($xml);

}

The XML file can be viewed here

http://manchester.studentdigz.com/properties.xml

Thank you all in advance, I appreciate all help!

4
  • 1
    This isn't just XML data. You seem to be consuming a SOAP service. Maybe you should rethink your approach and use something more adequate, i.e. SOAPClient to extract the information you need. Commented Mar 31, 2014 at 9:43
  • It seems SOAP is not available on the server where the site is hosted, any other ideas? Commented Mar 31, 2014 at 10:32
  • yes, use DOMXPath Commented Mar 31, 2014 at 12:26
  • I will give it a try and let you know in the morning, regards, Kris Commented Mar 31, 2014 at 15:24

1 Answer 1

1

You can use php simplexml (http://php.net/manual/en/book.simplexml.php) to load the string in an object.

Note that if you really want an array you could as well do :

$xml = simplexml_load_string($xmlstring)->children('http://schemas.xmlsoap.org/soap/envelope/')->children('Body');
$json = json_encode($xml);
$array = json_decode($json,TRUE);

echo "<pre>";
echo "xml object : <br/>"; 
var_dump($xml);
echo "<hr/>";
echo "json string : <br/>"; 
var_dump($json);
echo "<hr/>";
echo "array : <br/>"; 
var_dump($array);
Sign up to request clarification or add additional context in comments.

2 Comments

I've tried that and I just get an empty object/empty array?Thanks for the quick reply
xml object : object(SimpleXMLElement)#2 (1) { ["Body"]=> object(SimpleXMLElement)#4 (0) { } } json string : string(2) "{}" array : array(0) { }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.