ID: 42092 Updated by: [EMAIL PROTECTED] Reported By: paul at christianpatriot dot us -Status: Open +Status: Bogus Bug Type: SimpleXML related Operating System: Linux PHP Version: 5.2.3 New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Your code looks wrong: simplexml_load_file() already creates an instance of the object, you don't have to create an instance of SimpleXMLElement yourself. Previous Comments: ------------------------------------------------------------------------ [2007-07-25 03:34:28] paul at christianpatriot dot us Description: ------------ Attempting to append child/attributes to an existing xml file using post data from an html form. Post data gets passed fine, but it seems the xml file is never opened or loaded. Since I don't think the file is ever opened, I am unable to (attempt to) write the new data to the file. Reproduce code: --------------- processgb.php <?php $xml = simplexml_load_file('gbook.xml'); $sxe = new SimpleXMLElement($xml); $entry=$sxe->addChild('entry'); $entry->addAttribute('date',date("Y-m-d")); $entry->addChild('name',$_POST["name"]); $entry->addChild('email',$_POST["email"]); $entry->addChild('homepage',$_POST["homepage"]); $entry->addChild('country',$_POST["country"]); $entry->addChild('comment',$_POST["comment"]); $result=file_put_contents($sxe,"gbook.xml"); if ($result<1 or result==false): echo 'error writing: '.$result; endif; ?> XML structure: <?xml version="1.0" encoding="utf-8" ?> <guestbook> <entry date=""> <name></name> <email></email> <homepage></homepage> <country></country> <comment></comment> </entry> </guestbook> Expected result: ---------------- The new data is added to the xml file. Actual result: -------------- PHP Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /usr/local/apache2/htdocs/ssa/9112001/guestbook/processgb.php:9 Stack trace: #0 /usr/local/apache2/htdocs/ssa/9112001/guestbook/processgb.php(9): SimpleXMLElement->__construct('') #1 {main} thrown in /usr/local/apache2/htdocs/ssa/9112001/guestbook/processgb.php on line 9 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42092&edit=1
