nish
nish

Reputation: 7280

parser error : Start tag expected, '<' not found

I am using PHP for the first time. I am using the php sample for uploading image on ebay sandbox. I am getting the following error on running the PHP file:

PHP Warning:  simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 69
PHP Warning:  simplexml_load_string(): HTTP/1.1 200 OK in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 69
PHP Warning:  simplexml_load_string(): ^ in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 69
PHP Notice:  Trying to get property of non-object in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 92
PHP Notice:  Trying to get property of non-object in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 93
PHP Notice:  Trying to get property of non-object in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 93
PHP Notice:  Trying to get property of non-object in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 94
PHP Notice:  Trying to get property of non-object in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 94

Relevant lines are:

69. $respXmlObj = simplexml_load_string($respXmlStr);     // create SimpleXML object from string for easier parsing
                                                      // need SimpleXML library loaded for this

92. $ack        = $respXmlObj->Ack;
93. $picNameOut = $respXmlObj->SiteHostedPictureDetails->PictureName;
94. $picURL     = $respXmlObj->SiteHostedPictureDetails->FullURL;

What I can understand is the respXMLObj is not getting set properly. I have checked that simleXML support is enabled.

Could someone please help me debug this. Thanks

Upvotes: 12

Views: 115600

Answers (5)

five
five

Reputation: 21

Try to use simplexml_load_file('localpath') instead of simplexml_load_string(). I have had the same problem today (9 years later), and this was my solution.

Upvotes: 2

Danilo Bruno
Danilo Bruno

Reputation: 1

$hasError = false;

if ( $resp == 'Internal Server Error' || empty($resp) )
{
    $hasError = true;
}

if ( ! $hasError )
{                      
    $aux    = !empty($resp) ? explode('', $resp) : NULL;
    $temp   = utf8_decode(trim($aux[0]));               
    $xml    = simplexml_load_string($temp); 
}

Upvotes: 0

Ruslan Novikov
Ruslan Novikov

Reputation: 1527

In my case. I just removed the invisible character The BOM in the beginning of the XML file. How to do it - depends on your text editor.

Upvotes: 0

Bart Friederichs
Bart Friederichs

Reputation: 33531

The code you refer to has this line:

//curl_setopt($connection, CURLOPT_HEADER, 1 ); // Uncomment these for debugging

it seems like you uncommented these. This will result in getting the HTTP header in your response. Which is OK for debugging, but it will create an XML parse error in simplexml_load_string.

Either comment it out again or put 0 as its value.

Upvotes: 15

aland
aland

Reputation: 2004

Do a var_dump($respXmlStr); my guess is that this string is not valid XML.

As per the simplexml-load-string documentation, the first parameter is expected to be A well-formed XML string - http://php.net/manual/en/function.simplexml-load-string.php

Upvotes: -1

Related Questions