Parser Error Document Is Empty Simplexml_load_file
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 1 parser error document is empty Stack Overflow the company Business Learn more about hiring developers or posting ads with
:1: Parser Error : Document Is Empty Libreoffice
us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a simplexml_load_string community of 6.2 million programmers, just like you, 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
File_get_contents
so I'm grabbing some information from an XML file like so: $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 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);
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 more about hiring developers or posting ads with us http://stackoverflow.com/questions/11633810/catching-php-errors-if-xml-file-is-empty 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 takes a minute: Sign up Parsing a http://stackoverflow.com/questions/15787198/parsing-a-xml-file-using-simplexml-load-file-return-empty-object XML file using simplexml_load_file return empty object up vote 3 down vote favorite 1
for Help Receive Real-Time Help Create a Freelance Project Hire for http://forums.devnetwork.net/viewtopic.php?f=1&t=80015 a Full Time Job Ways to Get Help Ask a Question Ask for Help parser error Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to Get Help Expand Search Submit Close Search Login Join Today Products BackProducts document is empty Gigs Live Careers Vendor Services Groups Website Testing Store Headlines Experts Exchange > Error Experts Exchange Error Question Deleted This question has been deleted and cannot be viewed. Membership How it Works Gigs Live Careers Plans and Pricing For Business Become an Expert Resource Center About Us Who We Are Join Our Team Blog Contact Us Advertise Affiliates Mobile App Reviews © 1996-2016 Experts Exchange, LLC. All rights reserved. Covered by US Patent. Privacy Policy Site Map Support Terms of Use
index All times are UTC - 5 hours Information The requested topic does not exist. Board index All times are UTC - 5 hours Powered by phpBB Forum Software © phpBB Group