note 67453 added to function.dom-domimplementation-createdocumenttype
| From: | bjorn-AT-ambientchill-DOT--COM- at osu1 dot php dot net | Date: | Wed, 07 Jun 2006 23:44:42 +0000 |
| Subject: | note 67453 added to function.dom-domimplementation-createdocumenttype | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-113717@lists.php.net to get a copy of this message | ||
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.
?>
----
Server IP: 64.71.164.2
Probable Submitter: 70.171.219.145
----
X-Spam-Status: No, hits=4.7 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_20_30,HTML_MESSAGE,HTML_TAG_BALANCE_HTML autolearn=no
version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.dom-domimplementation-createdocumenttype.php
Edit -- http://master.php.net/note/edit/67453
Del: integrated -- http://master.php.net/note/delete/67453/integrated
Del: useless -- http://master.php.net/note/delete/67453/useless
Del: bad code -- http://master.php.net/note/delete/67453/bad+code
Del: spam -- http://master.php.net/note/delete/67453/spam
Del: non-english -- http://master.php.net/note/delete/67453/non-english
Del: in docs -- http://master.php.net/note/delete/67453/in+docs
Del: other reasons-- http://master.php.net/note/delete/67453
Reject -- http://master.php.net/note/reject/67453
Search -- http://master.php.net/manage/user-notes.php