downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

DOMImplementation::createDocumentType> <DOMImplementation::__construct
[edit] Last updated: Fri, 17 May 2013

view this page in

DOMImplementation::createDocument

(PHP 5)

DOMImplementation::createDocument Crea un objeto DOMDocument del tipo especificado con su elemento documento

Descripción

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

Crea un objeto DOMDocument del tipo especificado con su elemento documento.

Parámetros

namespaceURI

La URI del espacio de nombres del elemento documento a crear.

qualifiedName

El nombre cualificado del elemento documento a crear.

doctype

El tipo de documento a crear o NULL.

Valores devueltos

Un nuevo objeto DOMDocument. Si namespaceURI, qualifiedName, y doctype son null, el DOMDocument devuelto está vacío sin elemento documento

Errores/Excepciones

DOM_WRONG_DOCUMENT_ERR

Lanzado si doctype ya ha sido usado con un documento diferente o fue creado desde una implementación diferente.

DOM_NAMESPACE_ERR

Lanzado si hay un error con el espacio de nombres, como determina namespaceURI y qualifiedName.

Este método puede ser llamado de forma estática, pero lanzará un error E_STRICT.

Ver también



add a note add a note User Contributed Notes DOMImplementation::createDocument - [2 notes]
up
1
eboyjr
2 years ago
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>
up
0
arturm at union dot com dot pl
7 years ago
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);
?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites