Ver Mensaje Individual
  #4 (permalink)  
Antiguo 30/11/2010, 13:48
Avatar de masterpuppet
masterpuppet
Software Craftsman
 
Fecha de Ingreso: enero-2008
Ubicación: Montevideo, Uruguay
Mensajes: 3.550
Antigüedad: 16 años, 3 meses
Puntos: 845
Respuesta: insertar registro al principio de un xml

Con DOM seria algo asi:

Código PHP:
Ver original
  1. try {
  2.  
  3.      $dom = new DOMDocument();          
  4.      $dom->load('simple.xml');
  5.  
  6.      $node = $dom->createElement('noticia');        
  7.      $node->setAttribute('id',  $Nid);  
  8.      $node->setAttribute('titulo', $Ntitulo);    
  9.      $node->setAttribute('fecha', $Nfecha);    
  10.      $node->setAttribute('contenido', $Ncontenido);  
  11.  
  12.       $xpath  = new DOMXPath($dom);        
  13.       $first  = $xpath->query('//noticia[1]')->item(0);
  14.  
  15.       if(null === $first) {
  16.           $dom->documentElement->appendChild($node);            
  17.       } else {
  18.           $first->parentNode->insertBefore($node, $first);
  19.       }
  20.  
  21.       $dom->save('simple.xml');
  22.  
  23. } catch(Exception $e) {
  24.       //handle exception
  25. }

Salu2.