解析器错误:期望开始标记,'<'未找到

时间:2013-12-06 12:26:18

标签: php xml simplexml

我第一次使用PHP。我正在使用php示例在ebay沙箱上上传图片。我在运行PHP文件时遇到以下错误:

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

相关的行是:

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;

我能理解的是respXMLObj没有正确设置。我已经检查过启用了simleXML支持。

请有人帮我调试一下。感谢

4 个答案:

答案 0 :(得分:11)

您引用的代码包含以下行:

//curl_setopt($connection, CURLOPT_HEADER, 1 ); // Uncomment these for debugging
好像你没有注释这些。这将导致在您的响应中获取HTTP标头。哪个可以调试,但它会在simplexml_load_string中创建XML解析错误。

再次发表评论或将0作为其值。

答案 1 :(得分:0)

就我而言。我只是删除了XML文件开头的隐藏字符BOM 。怎么做 - 取决于你的文本编辑器。

答案 2 :(得分:0)

B2

答案 3 :(得分:-1)

我的猜测是var_dump($respXmlStr);这个字符串不是有效的XML。

根据simplexml-load-string文档,第一个参数应为A well-formed XML string - http://php.net/manual/en/function.simplexml-load-string.php