DOMImplementation::createDocument

(No version information available, might be only in CVS)

DOMImplementation::createDocument — Creates a DOMDocument object of the specified type with its document element

Описание

DOMDocument DOMImplementation::createDocument ([ string $namespaceURI [, string $qualifiedName [, DOMDocumentType $doctype ]]] )

Creates a DOMDocument object of the specified type with its document element.

Список параметров

namespaceURI

The namespace URI of the document element to create.

qualifiedName

The qualified name of the document element to create.

doctype

The type of document to create or NULL.

Возвращаемые значения

A new DOMDocument object. If namespaceURI , qualifiedName , and doctype are null, the returned DOMDocument is empty with no document element

Errors/Exceptions

DOM_WRONG_DOCUMENT_ERR

Raised if doctype has already been used with a different document or was created from a different implementation.

DOM_NAMESPACE_ERR

Raised if there is an error with the namespace, as determined by namespaceURI and qualifiedName .

Коментарии

To create HTML document with doctype:

<?php
$doctype 
DOMImplementation::createDocumentType("html",
               
"-//W3C//DTD HTML 4.01//EN",
               
"http://www.w3.org/TR/html4/strict.dtd");
$doc DOMImplementation::createDocument(null'html'$doctype);
?>
2006-05-06 13:23:14
http://php5.kiev.ua/manual/ru/domimplementation.createdocument.html
Автор:
To add on to the other example, here's how to create an XHTML 1.0 transitional document with head, title, and body elements.

<?php

$document 
DOMImplementation::createDocument(null'html',
   
DOMImplementation::createDocumentType("html"
       
"-//W3C//DTD XHTML 1.0 Transitional//EN"
       
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"));
$document->formatOutput true;

$html $document->documentElement;
$head $document->createElement('head');
$title $document->createElement('title');
$text $document->createTextNode('Title of Page');
$body $document->createElement('body');

$title->appendChild($text);
$head->appendChild($title);
$html->appendChild($head);
$html->appendChild($body);

echo 
$document->saveXML();
?>

This outputs: (http links removed due to spam)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "doctype.dtd"> 
<html xmlns="w3org1999xhtml"> 
  <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <title>Title of Page</title> 
  </head> 
  <body></body> 
</html> 

Note the saveXML function. If saveHTML was used instead, you get the output:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "doctype.dtd"> 
<html> 
<head><title>Title of Page</title></head> 
<body></body> 
</html>
2010-07-22 03:48:08
http://php5.kiev.ua/manual/ru/domimplementation.createdocument.html
I just recently got an error, having to do with deprecation, by using the type of calls in the other example listed here.  What I had to do instead looks like this...

$htmldoc = (new DOMImplementation)->createDocument(null, 'html', (new DOMImplementation)->createDocumentType("html"));

This creates a document with <!DOCTYPE html> at the top of it.
2018-07-02 06:48:41
http://php5.kiev.ua/manual/ru/domimplementation.createdocument.html

    Поддержать сайт на родительском проекте КГБ