1

I am trying to get a XML response from an external service as shown below. Using php Curl to post info and receiving the response and trying to display in the browser.

However I get the following error:

XML Parsing Error: syntax error Location: Line Number 1, Column 1:
<?xml version="1.0" encoding="utf-8"?>
^

can you help me whats the source of this and what does this error imply?

This is my code:

<?php
header ("Content-type: text/xml");
//defining $vars here...not shonw for simplicity

$url = 'http://secure.leadexec.net/leadimport.asmx/LeadReceiver';
$myvars = '&VID=' . $lead_id . '&LID=' . '2' . '&AID=' . $lead_id . '&FirstName=' . $fname . '&LastName=' . $lname .
       '&Email=' . $email . '&MoveDate='. $move_date . '&Telephone=' . $phone . '&Address=' . $address . 
       '&Website=' . $website . '&Zip=' . $zipcode . '&ServicesNeeded=' . $services . '&RequestaQuote=' . $requestquote .
       '&NumberofEmployees=' . $no_of_employees . '&CompanyName=' . $company_name;

$ch = curl_init();
curl_setopt( $ch, CURLOPT_VERBOSE, 1); 
curl_setopt( $ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_TIMEOUT, 40); 
curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_POST, 1);
$response = curl_exec($ch);
if(curl_exec($ch) === false)
{
    echo 'Curl error: ' . curl_error($ch);
}
else
{
    echo 'Operation completed without any errors';
}

$oXML = new SimpleXMLElement($response);

foreach($oXML->entry as $oEntry){
    echo $oEntry->title . "\n";
}
if(curl_errno($ch))
print curl_error($ch);
else
print_r($response);
curl_close($ch);
?>
hakre
  • 193,403
  • 52
  • 435
  • 836
srini
  • 89
  • 4
  • 16
  • 1
    Well, what does your XML contain? What is at line 1 position 1? – Pekka Dec 27 '12 at 20:27
  • false Data_Errors No Data Supplied 0 0 false 0 – srini Dec 27 '12 at 20:29
  • Thats how the response should look like. – srini Dec 27 '12 at 20:30
  • Perhaps your browser (firefox I assume? ) doesn't like that there's no tag on top. – periklis Dec 27 '12 at 22:57
  • Please review your quesiton, I made some edits to it. Also please add the XML you added in a comment into your question instead (use code-formatting please). Also please provide a hex-dump of the first 128 bytes of your XML, see [How can I get a hex dump of a string in PHP?](http://stackoverflow.com/q/1057572/367456) – hakre Jan 01 '13 at 22:31

0 Answers0