How about, I'm trying to edit an .xml file using PHP and HTML, my problem is that when I edit a node it goes well, then the other nodes are deleted and remain empty. Here my complete code.
Book1.xml file
<?xml version="1.0" encoding="UTF-8"?>
<info>
<nombre>Paulo Coelho</nombre>
<libro>El demonio y la señorita Prym</libro>
<ano>2000</ano>
<editorial>Planeta</editorial>
<servidor>DropBox</servidor>
<formato>.epub</formato>
</info>
and my editor.php file
<?php
if(isset($_POST['submit'])) {
$data = simplexml_load_file('libros/libro1.xml');
$data->nombre=$_POST['nombre'];
$data->libro=$_POST['libro'];
$data->año=$_POST['año'];
$data->editorial=$_POST['editorial'];
$data->servidor=$_POST['servidor'];
$data->formato=$_POST['formato'];
$handle=fopen("libros/libro1.xml","wb");
fwrite($handle,$data->asXML());
fclose($handle);
}
$data=simplexml_load_file('libros/libro1.xml');
$info=$data->nombre;
$libro=$data->libro;
$año=$data->año;
$editorial=$data->editorial;
$servidor=$data->servidor;
$formato=$data->formato;
?>
<form action="" method="post">
<input type="text" name="nombre"> Escritor: <?php echo $info; ?>
<br>
<input type="text" name="libro"> Titulo del Libro: <?php echo $libro; ?>
<br>
<input type="text" name="año"> Año de Publicación: <?php echo $año; ?>
<br>
<input type="text" name="editorial"> Editorial: <?php echo $editorial; ?>
<br>
<input type="text" name="servidor"> Servidor: <?php echo $servidor; ?>
<br>
<input type="text" name="formato"> Formato: <?php echo $formato; ?>
<br>
<input type="submit" name="submit" value="submit">
</form>
My problem is that if I edit the format field adding another value for example: .ebook then it changes it, but the other nodes are empty.
Before editing the book1.xml file
<?xml version="1.0" encoding="UTF-8"?>
<info>
<nombre>Paulo Coelho</nombre>
<libro>El demonio y la señorita Prym</libro>
<ano>2000</ano>
<editorial>Planeta</editorial>
<servidor>DropBox</servidor>
<formato>.epub</formato>
</info>
After editing the book1.xml file using my form:
<?xml version="1.0" encoding="UTF-8"?>
<info>
<nombre></nombre>
<libro></libro>
<ano></ano>
<editorial></editorial>
<servidor></servidor>
<formato>.ebook</formato>
</info>
Only the field that I have edited is edited but the others disappear, You could tell me that I am doing wrong, Thank you very much.