Manipulando arquivo xml com simplexml - CRUD
O arquivo inserir.php é responsável por criar um nó usando a função addChild:
Arquivo: inserir.php
Arquivo: inserir.php
<?php
include_once("config.php");
$name = $_POST["name"];
$password = $_POST["password"];
$maxconnections = $_POST["maxconnections"];
$profiles = $_POST["profiles"];
if(!$name)
exit; //Returns null
$xml = simplexml_load_file(ARQUIVO); // $xml "aponta" para o nó raiz, i.e., <arquivo>
if(!$xml)
return; //Returns null
$obj = $xml->{'user-manager'}->{'auth-config'}->addChild("user");
$obj->addChild("name", $name );
$obj->addChild("password",$password );
$obj->addChild("max-connections", $maxconnections );
$obj->addChild("profiles", $profiles );
// Incluindo um atributo "formato" no elemento "data"
//$obj->addAttribute('formato', 'w3c');
$xml->asXML(ARQUIVO); // XML original com o novo elemento
include "proxy.php";
?>
Novo Comentário: