note 67453 deleted from function.dom-domimplementation-createdocumenttype by bjori
| From: | bjori@php.net | Date: | Thu, 08 Jun 2006 00:19:28 +0000 |
| Subject: | note 67453 deleted from function.dom-domimplementation-createdocumenttype by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-113723@lists.php.net to get a copy of this message | ||
Note Submitter: bjorn -AT- ambientchill -DOT- -COM-
Reason: bad code
----
This code I wrote will create a basic valid xhtml document:
<?php
class Document {
private $dom;
private $rootHTML;
private $head;
private $title;
private $body;
public function __construct(){
// Creates an instance of the DOMImplementation class
$imp = new DOMImplementation;
// Creates a DOMDocumentType instance
$fpi = '-//W3C//DTD XHTML 1.0 Strict//EN';
$dtdLocation = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";
$dtd = $imp->createDocumentType('html', $fpi, $dtdLocation);
// Creates a DOMDocument instance
$this->dom = $imp->createDocument("", "", $dtd);
$this->dom->encoding = 'UTF-8';
// Creating the root <html> element;
$this->rootHTML = $this->dom->createElement('html');
$this->dom->appendChild($this->rootHTML);
$this->head = $this->dom->createElement('head');
$this->rootHTML->appendChild($this->head);
$this->title = $this->dom->createElement('title','Ogre Masters');
$this->head->appendChild($this->title);
$this->body = $this->dom->createElement('body');
$this->rootHTML->appendChild($this->body);
return;
}
public function getDocument(){
return $this->dom->saveXML();
}
}
Creates:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta
http-equiv="Content-Type" content="text/html; charset=UTF-8"
/><title>Ogre Masters</title></head><body></body></html>
Interesting how if you create an HTML element it automatically adds the xmlns for xhtml.
?>