PHP | DOMDocument createAttributeNS() Function Last Updated : 29 Aug, 2019 Comments Improve Suggest changes Like Article Like Report 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 mentioned above and described below: $namespaceURI: This parameter holds the URI of the namespace. $qualifiedName This parameter holds the tag name and prefix of the attribute. For example: prefix:tagname. Return Value: This function returns a new DOMAttr object on success or FALSE on failure. Below program illustrates the DOMDocument::createAttributeNS() function in PHP: Program: php <?php // Store the XML document to the source $source = <<<XML <?xml version="1.0" encoding="UTF-8"?> <root><contact><email>[email protected]</email> <mobile>+91-987654321</mobile></contact></root> XML; // Create a new document $domDocument = new DOMDocument( '1.0' ); // Load the XML file $domDocument->loadXML( $source ); // Use createAttributeNS() function to create new attribute // node with an associated namespace $attrNS = $domDocument->createAttributeNS( '{namespace}', 'info:cont_info' ); // Create XML document and display it echo $domDocument->saveXML() . "\n"; // Assign value to the createAttributeNS $attrNS->value = 'https://www.geeksforgeeks.org/about/contact-us/'; $domDocument->getElementsByTagName( 'contact' ) ->item(0)->appendChild( $attrNS ); // Create XML document and display it print $domDocument->saveXML() . "\n"; ?> Output: <?xml version="1.0" encoding="UTF-8"?> <root xmlns:info="{namespace}"> <contact> <email>[email protected]</email> <mobile>+91-987654321</mobile> </contact> </root> <?xml version="1.0" encoding="UTF-8"?> <root xmlns:info="{namespace}"> <contact info:cont_info= "https://www.geeksforgeeks.org/about/contact-us/"> <email>[email protected]</email> <mobile>+91-987654321</mobile> </contact> </root> Reference: https://www.php.net/manual/en/domdocument.createattributens.php Comment More infoAdvertise with us Next Article PHP | DOMDocument createAttributeNS() Function J jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-DOM Similar Reads PHP | DOMDocument createAttribute() Function The DOMDocument::createAttribute() function is an inbuilt function in PHP which is used to create a new instance of class DOMAttr. Syntax: DOMAttr DOMDocument::createAttribute( string $name ) Parameters: This function accepts single parameter $name which holds the name of the attribute. Return Value 2 min read PHP | DOMDocument createCDATASection() Function The DOMDocument::createCDATASection() function is an inbuilt function in PHP which is used to create a new instance of class DOMCDATASection. Syntax: DOMCDATASection DOMDocument::createCDATASection( string $data ) Parameters: This function accepts single parameter $data which holds the content of th 1 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 createElementNS() Function 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 para 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