Я использую SimpleXML для добавления новых изображений дочерних элементов для инструмента слайд-шоу на моем веб-сайте, код выглядит примерно так:
$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);
Который отлично работает, чтобы добавить новый
<image attr="blabla"><caption>imageinfo</caption><image>
ребенок, внутри <imagegallery></imagegalley>
Однако мне нужно, чтобы этот childs шел сразу после <imagegallery>
, а не перед закрытием тега (один за другим), это заставляет появляться новые изображения в последнем месте слайд-шоу imagegallery.
Таким образом, новейшие дочерние элементы, которые я добавляю, должны идти до того, как они добавились в xml в последний раз, например
<imagegallery>
<image attr="HEREGOESTHENEWST">
<caption>description</caption>
</image>
<image attr="THEOLDONE">
<caption>description</caption>
</image>
</imagegallery>
Как мне этого добиться?