PHP | DOMImplementation createDocument() Function Last Updated : 26 Feb, 2020 Comments Improve Suggest changes Like Article Like Report The DOMImplementation::createDocument() function is an inbuilt function in PHP which is used to create a DOMDocument object of the specified type with its document element. Syntax: DOMDocument DOMImplementation::createDocument( string $namespaceURI = NULL, string $qualifiedName = NULL, DOMDocumentType $doctype = NULL ) Parameters: This function accepts three parameters as mentioned above and described below: $namespaceURI (Optional): It specifies the namespace URI of the document element to create. $qualifiedName (Optional): It specifies the qualified name of the document element to create. $doctype (Optional): It specifies the type of document to create or NULL. Return Value: This function returns DOMDocument object on success. Exceptions: This function throws DOM_WRONG_DOCUMENT_ERR, if doctype has already been used with a different document or was created from a different implementation or DOM_NAMESPACE_ERR, if there is an error with the namespace, as determined by $namespaceURI and $qualifiedName. Below examples illustrate the DOMImplementation::createDocument() function in PHP: Example 1: php <?php // Create a DOMImplementation instance $documentImplementation = new DOMImplementation(); // Create a document $document = $documentImplementation->createDocument(null, 'html'); // Get the document element $html = $document->documentElement; // Create a HTML element $head = $document->createElement('html'); // Create a strong element $title = $document->createElement('strong'); $text = $document->createTextNode('GeeksforGeeks'); $body = $document->createElement('body'); // Append the children $title->appendChild($text); $head->appendChild($title); $html->appendChild($head); $html->appendChild($body); // Render the XML echo $document->saveXML(); ?> Output: Example 2: php <?php // Create a DOMImplementation instance $documentImplementation = new DOMImplementation(); // Create a document $document = $documentImplementation->createDocument(null, 'html'); // Get the document element $html = $document->documentElement; // Create a HTML element $head = $document->createElement('html'); // Create a paragraph element $p = $document->createElement('p'); // Create a text node $text = $document->createTextNode('GeeksforGeeks'); // Append the children $p->appendChild($text); // Set the CSS using attribute $p->setAttribute('style', 'color:blue;font-size:100px'); // Append paragraph to the head of document $head->appendChild($p); // Append head to the html $html->appendChild($head); // Render the XML echo $document->saveXML(); ?> Output: Reference: https://www.php.net/manual/en/domimplementation.createdocument.php Comment More infoAdvertise with us Next Article PHP | DOMImplementation createDocument() Function G gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-DOM Similar Reads PHP | DOMImplementation createDocumentType() function The DOMImplementation::createDocumentType() function is an inbuilt function in PHP which is used to create an empty DOMDocumentType object. Entity declarations and notations are not available. Syntax: DOMDocumentType DOMImplementation::createDocumentType ( string $qualifiedName = NULL, string $publi 1 min read PHP | DOMImplementation __construct() Function The DOMImplementation::__construct() function is an inbuilt function in PHP which is used to create a new DOMImplementation object. Syntax: DOMImplementation::__construct( void ) Parameters: This function doesnât accept any parameter. Below examples illustrate the DOMImplementation::__construct() fu 1 min read PHP | DOMDocument createComment() Function The DOMDocument::createComment() function is an inbuilt function in PHP which is used to create a new instance of class createComment. Syntax: DOMComment DOMDocument::createComment( string $data ) Parameters: This function accepts single parameter $data which holds the content of the comment node. R 2 min read PHP | DOMDocument createDocumentFragment() Function The DOMDocument::createDocumentFragment() function is an inbuilt function in PHP which is used to create a new document fragment. Syntax: DOMDocumentFragment DOMDocument::createDocumentFragment( void ) Parameters: This function doesnât accepts any parameters. Return Value: This function returns a ne 2 min read PHP | DOMDocument createElement() Function The DOMDocument::createElement() function is an inbuilt function in PHP which is used to create a new instance of class DOMElement. Syntax: DOMElement DOMDocument::createElement( string $name, string $value ) Parameters: This function accepts two parameters as mentioned above and described below: $n 2 min read Like