XML writing problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chryu
Forum Newbie
Posts: 2
Joined: Thu Nov 01, 2007 7:03 pm

XML writing problems

Post 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!
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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.
chryu
Forum Newbie
Posts: 2
Joined: Thu Nov 01, 2007 7:03 pm

Post 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.
Post Reply