how to send data in xml without replacing the previous data

0

I have the following code, where I get event data from a form and php sends it to the xml file, however instead of the events.xml append new data when the form is populated again, it replaces the previous values with the new ones form, in the same tags.

<?php
#Obtendo dados dos eventos
$campoTitulo = $_POST['titulo'];
$campoLocal = $_POST['local'];
$campoData = $_POST['data'];
$campoHorario = $_POST['horario'];
$campoDescricao = $_POST['descricao'];
#versao do encoding xml
$dom = new DOMDocument("1.0", "UTF-8");
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$root = $dom->createElement("agenda");
$evento = $dom->createElement("evento");
#tags para evento
$nomeEvento = $dom->createElement("titulo", $campoTitulo);
$localEvento = $dom->createElement("local", $campoLocal);
$dataEvento = $dom->createElement("data", $campoData);
$horarioEvento = $dom->createElement("horario", $campoHorario);
$descricaoEvento = $dom->createElement("descricao", $campoDescricao);
#evento adiciona as tags criadas
$evento->appendChild($nomeEvento);
$evento->appendChild($localEvento);
$evento->appendChild($dataEvento);
$evento->appendChild($horarioEvento);
$evento->appendChild($descricaoEvento);
#root adiciona o nó evento
$root->appendChild($evento);
$dom->appendChild($root);
#salvando as informações no arquivo xml
$dom->save("eventos.xml");
header("Content-Type:text/xml");
print $dom->saveXML();
?>

xml file

<?xml version="1.0" encoding="UTF-8"?>
<agenda>
<evento>
<titulo>titulo</titulo>
<local>local</local>
<data>data</data>
<horario>10:00</horario>
<descricao>descricao do evento</descricao>
</evento>
</agenda>

I can not increment more events because xml only replaces the values in the

    
asked by anonymous 17.06.2018 / 06:09

1 answer

0

Try adding an id in each. So when you're adding another event, add it with a different id.

    
17.06.2018 / 07:03