what function would be useful to remove xml data with php or js?

Asked

Viewed 32 times

0

I’m making a system with php,js and xml,with a php form where the user adds events and they are automatically written to xml

This is the add.php

$campoTitulo = $_POST['titulo'];
$campoLocal = $_POST['local'];
$campoData = $_POST['data'];
$campoHorario = $_POST['horario'];
$campoDescricao = $_POST['descricao'];
//Nome do arquivo
$nomeArquivo = "eventos.xml";
// versão do encoding xml
$dom = new DOMDocument("1.0", "utf-8");
// retirar os espaços em branco
$dom->preserveWhiteSpace = false;
// gerar código ??
$dom->formatOutput = true;
// carrega o arquivo
$dom->load($nomeArquivo);
// recupera nó principal
$root = $dom->documentElement;

$evt = addEvento($dom, $campoTitulo, $campoLocal, $campoData, $campoHorario, 
$campoDescricao);
// adicionando ao root
$root->appendChild($evt);
$dom->appendChild($root);

// salva o arquivo
$dom->save($nomeArquivo);
// mostrar
header("Content-Type: text/xml");
print $dom->saveXML();

function addEvento($documento, $titulo, $local, $data, $horario, $descricao) {
// criar evento
$evt = $documento->createElement("evento");
// criar nó titulo
$tituloElm = $documento->createElement("titulo", $titulo);
//criar nó local
$localElm = $documento->createElement("local", $local);
// criar nó data
$dataElm = $documento->createElement("data", $data);
//criar nó horário
$horarioElm = $documento->createElement("horario", $horario);
//criar nó descrição
$descricaoElm = $documento->createElement("descrição", $descricao);

$evt->appendChild($tituloElm);
$evt->appendChild($localElm);
$evt->appendChild($dataElm);
$evt->appendChild($horarioElm);
$evt->appendChild($descricaoElm);
return $evt;
}
?>

But I need a script so that the user can remove his events through a form, where the events he created are shown (I already did), and a delete button for each event.

  • With her own class DOMDocument you parse the XML and remove the elements you want.

  • I’m still familiar with DOM and XML, so I have no clear ideas on how to manipulate Domdocument so that the user can remove their own data

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.