Consulta XML agregar no remplazar

  • Autor Autor Prospero
  • Fecha de inicio Fecha de inicio
Prospero

Prospero

Eta
Verificación en dos pasos activada
Hola gente tengo este code...

HTML
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Documento sin título</title></head>
<body><form method="post" action="cargarxml.php"><fieldset><legend>Llenar los datos</legend><label for="txtname">Nombre</label><input type="text" name="txtname" id="txtname" /><br /><br /><label for="txtApellido">Apellido</label><input type="text" name="txtApellido" id="txtApellido" /><br /><br /><label for="list">Pais</label><select name="pais" id="list"><option value="Peru">Peru</option><option value="Brasil">Brasil</option><option value="Bolivia">Bolivia</option></select><br /><br /><br /><input type="submit" value="Guardar" /></fieldset></form></body></html>

y el cargarxml.php

PHP:
<?php 
$name=$_POST['txtname']; $apelli=$_POST['txtApellido']; $pais=$_POST['pais']; 
if($name != "" && $apelli != "") {     $xml = new DomDocument('1.0', 'UTF-8');     $root = $xml->createElement('personas');     $root = $xml->appendChild($root);      	     $user=$xml->createElement('user');     $user =$root->appendChild($user);          $nom=$xml->createElement('nombre',$name);     $nom =$user->appendChild($nom);          $apellidonode=$xml->createElement('apellido',$apelli);     $apellidonode=$user->appendChild($apellidonode);          $paisnode=$xml->createElement('pais',$pais);     $paisnode=$user->appendChild($paisnode);          $xml->formatOutput = true; 
    $strings_xml = $xml->saveXML(); 
    $xml->save('usuarios.xml'); 
    echo 'Se guardo correctamente'; } else     echo 'Datos vacios'; 
?>


Anda genial pero me remplaza y no me guarda abajo del otro.. necesito guardar uno abajo del otro... no es como abrir los archivos que segun la letrita que le pongamos es lo que hace.. alguna solucion o donde puedo leer? graciass!
 
En lugar de usar $xml->save(); puedes usar fopen para crear el archivo y agregarle el XML sin reemplazarlo.
 
Atrás
Arriba