0

Possible Duplicate:
A simple program to CRUD node and node values of xml file

I am trying to create a form that will allow me to add new records in an xml file using php and xml dom. The xml file is on the server and i want the client to be able to type in and add to the xml file. Heres my code so far

$data = "books.xml";

$xml = simplexml_load_file($data);
$book = $xml->addChild("book");
$author = $_POST["author"];
$title = $_POST["title"];
$publisher = $_POST["publisher"];
$book->addChild("author", $author);
$book->addChild("title", $title);
$book->addChild("publisher", $publisher);

echo $xml->saveXML();

The form

<form action="addchild.php" method="post">
Name: <input type="text" name="author" />
Email: <input type="text" name="title" />
Comment: <input type="text" name="publisher" />
<input type="submit" />
</form>

The XML

<books>
<book>
<author>Jack Herrington</author>
<title>PHP Hacks</title>
<publisher>O'Reilly</publisher>
  </book>
<book>
<author>Jack Herrington</author>
<title>Podcasting Hacks</title>
<publisher>O'Reilly</publisher>
</book>
</books>
Community
  • 1
  • 1

0 Answers0