Page 1 of 1

XML writing problems

Posted: Thu Nov 01, 2007 7:21 pm
by chryu
Hi all,

I've got a strange XML problem, and I've got no idea where to start looking. Writing to an XML file worked fine when I used DOM methods, but I've switched to the simplexml method of loading it and then saving it with

Code: Select all

file_put_contents('filename.xml', $xml->asXML())
What happened recently was everything was cleared out of the XML file except for this line:

Code: Select all

<?xml version="1.0"?>
where previously, there was an internal DTD plus the root element and all its children.

Now I have no idea what could cause this, but I suspect it has something to do with

Code: Select all

file_put_contents()
or the output from simplexml. Can anyone give me some place to start looking or how to figure out what's causing the problem? So far, this has only happened once, so I can't really test any solutions immediately, as I don't know how to reproduce the behavior. I can post more code if it will help.

Thanks!

Posted: Thu Nov 01, 2007 9:31 pm
by Kieran Huggins
my instincts tell me to make sure there's a single root element - I recall PHP having strange behaviour like this when there are multiple roots (read: no root).

I'm probably wrong.

Posted: Sat Nov 03, 2007 9:08 pm
by chryu
If anyone's wondering, I've been able to reproduce the behavior by loading and saving an XML file with DOM methods multiple times simultaneously. In my case, I use XML as storage, so when users deleted comments too quickly, it caused this error.