On Sat, 2010-07-03 at 18:58 +0100, te0t3l wrote:

> Hi, I have a photo gallery and I update it with a XML file like this:
> $NuevaCol = new SimpleXMLElement("../xml/" . $coleccionXML . '.xml', null,
> true);
> $first = $NuevaCol->addChild('coleccion');
> $attsNuevaCol = $first->addAttribute('nombre_col',
> utf8_encode($titNuevaColEspacios));
> $attsNuevaCol = $first->addAttribute('archivo', utf8_encode($uploadDir .
> $nombreMiniatura));
> $NuevaCol->asXML("../xml/" . $coleccionXML . '.xml');
> Now I try to include the new Child at the begining of the document because I
> want that the last update will be show the first in the gallery, do me
> explain?
> How can I do it?,
> Thanks in advance,
> te0

First, please use a subject, as a lot of email clients can only thread
emails by the subject, and it helps the archives too.

What I believe you're looking for is the insertBefore() method, which
you can use to add an element before an existing one in the DOM. You're
already reading in the DOM from the xml file, so you just need to find
the first <coleccion> element and use insertBefore() add the new one
before it, then output the whole DOM again into the xml file.


Reply via email to