<?php
Class books extends domDocument {
function __construct() {
parent::__construct();
}
function addBook($title, $author) {
$titleElement = $this->createElement("title");
$titleElement->appendChild($this->createTextNode($title));
$authorElement = $this->createElement("author");
$authorElement->appendChild($this->createTextNode($author));
$bookElement = $this->createElement("book");
$bookElement->appendChild($titleElement);
$bookElement->appendChild($authorElement);
$this->documentElement->appendChild($bookElement);
}
}
header("Content-type: text/xml");
$dom = new books();
$dom->load("test.xml");
$dom->addBook("PHP 5", "Kgougakis, Php5");
print $dom->saveXML();
?>