|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42092 Unable to open xml via SimpleXML
Submitted: 2007-07-25 03:34 UTC Modified: 2007-07-25 14:28 UTC
From: paul at christianpatriot dot us Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.2.3 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
26 - 21 = ?
Subscribe to this entry?

 [2007-07-25 03:34 UTC] paul at christianpatriot dot us
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:
$xml = simplexml_load_file('gbook.xml');
$sxe = new SimpleXMLElement($xml);
$result=file_put_contents($sxe,"gbook.xml"); if ($result<1 or result==false): echo 'error writing: '.$result;

XML structure:
<?xml version="1.0" encoding="utf-8" ?>
<entry date="">

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-25 14:28 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

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.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Sep 23 07:01:25 2023 UTC