PHP DOMDocument createElementNS() Function Last Updated : 03 Apr, 2023 Comments Improve Suggest changes Like Article Like Report The DOMDocument::createElementNS() function is an inbuilt function in PHP that is used to create a new element node with an associated namespace. Syntax: DOMElement DOMDocument::createElementNS( string $namespaceURI, string $qualifiedName, string $value ) Parameters: This function accepts three parameters as mentioned above and described below: $namespaceURI: This parameter holds the URI of the namespace.$qualifiedName: This parameter holds the qualified name of the element, as prefix:tagname.$value: This parameter holds the value of the element. The default value of this parameter is empty or none, means an empty element created. Return Value: This function returns the new DOMElement on success or FALSE on failure. Below examples illustrate the DOMDocument::createElementNS() function in PHP: Example 1: php <?php // Create a new DOMDocument $dom = new DOMDocument('1.0', 'utf-8'); // Use createElementNS() function to create new // element node with an associated namespace $element = $dom->createElementNS('https://www.geeksforgeeks.org/php', 'php:function', 'Welcome to GeeksforGeeks'); // Append the child element $dom->appendChild($element); // Create XML document and display it echo $dom->saveXML(); ?> Output:<?xml version="1.0" encoding="utf-8"?> <php:function xmlns:php="https://www.geeksforgeeks.org/php"> Welcome to GeeksforGeeks </php:function> Example 2: php <?php // Create a new DOMDocument $dom = new DOMDocument('1.0', 'utf-8'); // Use createElementNS() function to create new // element node with an associated namespace $element1 = $dom->createElementNS('https://www.geeksforgeeks.org/php', 'organization:GeeksforGeeks', 'A computer science portal'); $element2 = $dom->createElementNS('https://www.geeks.org/html', 'php:link', 'Welcome to GeeksforGeeks'); $element3 = $dom->createElementNS('https://www.geeksforgeeks.org/algo', 'algo:link', 'Best coding platform'); // Append the child element $dom->appendChild($element1); $dom->appendChild($element2); $dom->appendChild($element3); // Create XML document and display it echo $dom->saveXML(); ?> Output:<?xml version="1.0" encoding="utf-8"?> <organization:GeeksforGeeks xmlns:organization ="https://www.geeksforgeeks.org/php"> A computer science portal </organization:GeeksforGeeks> <php:link xmlns:php="https://www.geeks.org/html"> Welcome to GeeksforGeeks </php:link> <algo:link xmlns:algo="https://www.geeksforgeeks.org/algo"> Best coding platform </algo:link> Reference: https://www.php.net/manual/en/domdocument.createelementns.php Comment More infoAdvertise with us Next Article PHP DOMDocument createElementNS() Function J jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-DOM Similar Reads 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 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 createTextNode() Function The DOMDocument::createTextNode() function is an inbuilt function in PHP which is used to create a new instance of class DOMText. Syntax: DOMText DOMDocument::createTextNode( string $content ) Parameters: This function accepts single parameter $content which holds the content of the text. Return Val 1 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 createAttributeNS() Function The DOMDocument::createAttributeNS() function is an inbuilt function in PHP which is used to create a new attribute node with an associated namespace. Syntax: DOMAttr DOMDocument::createAttributeNS( string $namespaceURI, string $qualifiedName ) Parameters: This function accepts two parameters as men 2 min read Like