buffer = new DOMDocument('1.0', 'utf-8');
$this->buffer->appendChild( new DOMElement('html') );
}
public function makeTitle ($title) {
$html = $this->getUniqueNodeByTagName('html');
$head = $html->appendChild( new DOMElement('head') );
$titleNode = $head->appendChild( new DOMElement('title', $title) );
}
public function makeString ($string) {
$body = $this->getBody();
$body->appendChild( new DOMElement('p', $string) );
}
public function makeItems ($items) {
$body = $this->getBody();
$ul = $body->appendChild( new DOMElement('ul') );
foreach($items as $item) {
$ul->appendChild( new DOMElement('li', $item) );
}
}
public function close () {
// doing nothing.
}
public function getResult () {
return $this->buffer->saveXML();
}
private function &getUniqueNodeByTagName ($tagName, $index = 0 ) {
$tmp = $this->buffer->getElementsByTagName($tagName);
return $tmp->item($index);
}
private function &getBody () {
$tmp = $this->buffer->getElementsByTagName('body');
if ( $tmp->length ) {
return $tmp->item(0);
} else {
$html = $this->getUniqueNodeByTagName('html');
$html->appendChild(new DOMElement('body'));
return $this->getUniqueNodeByTagName('body');
}
}
}