Im using SimpleXML to add new images childs for a slideshow tool on my website, the code is something like this:
$xml_toload = $_SERVER['DOCUMENT_ROOT']. '/xml/'.$country.'/compact.xml';
$xml = simplexml_load_file($xml_toload); //This line will load the XML file.
$sxe = new SimpleXMLElement($xml->asXML());
//In this line it create a SimpleXMLElement object with the source of the XML file.
//The following lines will add a new child and others child inside the previous child created.
$image = $sxe->addChild('image');
$image->addAttribute('imageURL',$file);
$image->addAttribute('thumbURL',$file);
$image->addAttribute('linkURL',$linkurl);
$image->addAttribute('linkTarget',$linkurl);
$image->addChild('caption',$caption);
$sxe->asXML($xml_toload);
Which is working perfectly to add the new
<image attr="blabla"><caption>imageinfo</caption><image>
child, inside of <imagegallery></imagegalley>
But I have a serious problem, I need this childs to go just after <imagegallery>
, not before the tag is closed, (one after other), this makes to appear new images, at the last place on the imagegallery slideshow.
So the newest chids that I add, should go before the last it has added to the xml, like
<imagegallery>
<image attr="HEREGOESTHENEWST">
<caption>description</caption>
</image>
<image attr="THEOLDONE">
<caption>description</caption>
</image>
</imagegallery>
Anyone can help me with a clear example? Thank you, its urgent!