Php Xml Parser Error Document Is Empty
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn 1 parser error document is empty more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags
:1: Parser Error : Document Is Empty Libreoffice
Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you,
Simplexml_load_file
helping each other. Join them; it only takes a minute: Sign up Catching PHP errors if XML file is empty up vote 1 down vote favorite 1 so I'm grabbing some information from an XML file like so:
Simplexml_load_string
$url = "http://myurl.blah"; $xml = simplexml_load_file($url); Except sometimes the XML file is empty and I need the code to fail gracefully but I can't seem to figure out how to catch the PHP error. I tried this: if(isset(simplexml_load_file($url))); { $xml = simplexml_load_file($url); /*rest of code using $xml*/ } else { echo "No info avilable."; } But it doesn't work. I guess you can't use ISSET that way. Anyone know how to catch the error? php xml xml validator error-handling share|improve this question asked Jul 24 '12 at 15:07 AzzyDude 1,00432448 Catch what error? –mellamokb Jul 24 '12 at 15:10 1 In general, you can use the try {} catch (exception $e) {} pair. –Scott S Jul 24 '12 at 15:10 2 simplexml_load_file() does not throw exceptions. It raises E_WARNING errors. –Florent Jul 24 '12 at 15:12 @mellamokb The PHP error informing me that the file is empty. What else? –AzzyDude Jul 24 '12 at 15:12 To be exact: Warning: simplexml_load_file() [function.simplexml-load-file]: myurl.blah:1: parser error : Document is empty in blah... –AzzyDude Jul 24 '12 at 15:14 | show 1 more comment 4 Answers 4 active oldest votes up vote 7 down vote accepted $xml = file_get_contents("http://myurl.blah"); if (trim($xml) == '') { die('No content'); } $xml = simplexml_load_string($xml); Or, possibly slightly more efficient, but not necessarily recommended because it silences errors: $xml = @simplexml_load_file($url); if (!$xml) { die('error'); } share|improve this answer answered Jul 24 '12 at 15:12 deceze 304k44386531 add a comment| up vote 1 down vote Don't use isset here. // Shutdown errors (I know it's bad) $xml = @simplexml_load_file($url); // Check you have fetch a response if (false !== $xml); { //rest of code using $xml } else { echo "No info avilable."; } share|improve this answer answered Jul 24 '12 at 15:11 Fl
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and php try catch policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only http://stackoverflow.com/questions/11633810/catching-php-errors-if-xml-file-is-empty takes a minute: Sign up simplexml_load_file() error up vote 4 down vote favorite I'm relatively new with PHP and more so with XML. I have a script working perfectly on my localhost, but when I try and put it on my Server, I get this message: Warning: simplexml_load_file() [function.simplexml-load-file]: http://api.wefeelfine.org:8080/ShowFeelings?display=xml&feeling=happy&returnfields=imageid,feeling,sentence,posttime,postdate,posturl,gender,country,state,city,lat,lon&limit=0&extraimages=20:1: parser error : Document is empty in /home2/alsweet/public_html/notalone.php on line 21 http://stackoverflow.com/questions/4298866/simplexml-load-file-error The line of code which is not working is this: // get api feed $xml = simplexml_load_file('http://api.wefeelfine.org:8080/ShowFeelings?display=xml&feeling=' . $feeling . '&returnfields=imageid,feeling,sentence,posttime,postdate,posturl,gender,country,state,city,lat,lon&limit=0&extraimages=20'); Have I made a mistake? Should I be speaking to my hosting provider? php simplexml share|improve this question edited Aug 31 '15 at 13:30 Nirav Zaveri 3771419 asked Nov 28 '10 at 20:22 alsweet 332622 add a comment| 3 Answers 3 active oldest votes up vote 1 down vote Using the url you have in your xml loader I get:
The SitePoint Forums have moved. You can now find http://www.sitepoint.com/forums/showthread.php?612853-SimpleXML-errors them here. This forum is now closed to new posts, but you can browse existing content. You can find out more information about the http://blog.jdlh.com/en/2009/02/08/joomla_xml_parsing_error/ move and how to open a new account (if necessary) here. If you get stuck you can get support by emailing forums@sitepoint.com If parser error this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection document is empty below. SitePoint Sponsor User Tag List Results 1 to 2 of 2 Thread: SimpleXML errors Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Apr 24, 2009,03:12 #1 SJH View Profile View Forum Posts SitePoint Wizard Join Date Mar 2002 Location Bristol, UK Posts 2,240 Mentioned 0 Post(s) Tagged 0 Thread(s) SimpleXML errors Hi everyone, Having a few problems parsing an XML file using SimpleXML. PHP Code: $xmlstr=simplexml_load_file('http://feeds.feedburner.com/BloggerFCO');
The above code results in the following errors: Code: Warning: simplexml_load_file() [function.simplexml-load-file]: http://feeds.feedburner.com/BloggerFCO:1: parser error : Document is empty in /home/civicsur/public_html/local/task/test/feedtest.php on line 3 Warning: simplexml_load_file() [function.simplexml-load-file]: in /home/civicsur/public_html/local/task/test/feedtest.php on line 3 Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /home/civicsur/public_html/local/task/test/feedtest.php on
Error at 1:1. Error 4: Empty document" when installing a Joomla template or extension Posted by Jim DeLaHunt on 08 Feb 2009 at 11:21 pm | Tagged as: Joomla, robobait Recently, I remodelled a Joomla template for one of my clients. As I was installing newer versions of the template, I noticed an error message started appearing on installation: XML Parsing Error at 1:1. Error 4: Empty document However, the installation seemed to be successful. And I had a valid templateDetails.xml file in my template's .zip file. There was a Joomla! forum thread "XML Parsing Error at 1:1. Error 4: Empty document" dating from December 28, 2008 about this problem, so it wasn't just me. Here is my diagnosis of the problem, and my solution. Since this is one of those problems that drove me crazy, I'm going to put my findings here in hopes that search engines will find it and bring it to others who might benefit from the tip. Hence, it's tagged "robobait". The short answer: the error message comes from a metadata file named ._templateDetails.xml, which the Mac OX 10.5.x Finder inserted into the ZIP archive. This file didn't have XML content, but the Joomla installer interpreted it as such. And the content it did have, happened to be the kind of invalid content that provoked an error message instead of silent failure. The immediate solution is to generate the ZIP file in such a way that there is no metadata file named ._templateDetails.xml . Long-term, it would be nice if Joomla! would not display an error message in this situation. Read on for more about the problem, the diagnosis, and possible solutions. The installable archive structure Joomla templates (and other extensions like modules and plugins) are structured as a compressed archive (.zip, .tar.gz, or .tar.bz2 formats all work) containing the various files of the extension, plus an XML-format file which gives meta-information about the extension. This meta-information includes the name of the extension, the version number, a