I'm trying to add a comment list to a page using an xml file. I'd like to list the comments most recent first, so when a new comment is added, I'd like to add it to the start of the xml. addChild appends to the end, so that's no good, and I can't get my head around the the DOMNode insert_before method, as I want to add it at the start before every other occurrence of a child (and I can't find an example anywhere that does this - weird).
xml file looks like;
<comments>
<comment>
<date>20130625</date>
<name>Jocky Wilson</name>
<text>Something about darts presumably</text>
</comment>
<comment>
<date>20130622</date>
<name>Jacky Wilson</name>
<text>It was reet petite etc</text>
</comment>
</comments>
I create the file initially with;
<?php
$xmlData = "< load of xml etc...";
$xml = new SimpleXMLElement($xmlData);
file_put_contents("comments.xml", $xml->asXML());
?>
And that works fine. Any suggestions at all gratefully received.