PHP | DOMElement setIdAttributeNS() Function Last Updated : 26 Feb, 2020 Comments Improve Suggest changes Like Article Like Report The DOMElement::setIdAttributeNS() function is an inbuilt function in PHP which is used to declare the attribute specified by given local name and namespace URI to be of type ID. Syntax: void DOMElement::setIdAttributeNS( string $namespaceURI, string $localName, bool $isId ) Parameters: This function accept three parameters as mentioned above and described below: $namespaceURI: It specifies the namespace URI. $localName: It specifies the local name. $isId: It specifies whether if you want name to be of type ID. Return Value: This function returns nothing. Exceptions: This function throws DOM_NO_MODIFICATION_ALLOWED_ERR, if the node is readonly or DOM_NOT_FOUND, if name is not an attribute of this element. Below examples illustrate the DOMElement::setIdAttributeNS() function in PHP: Example 1: php <?php // Create a new DOMDocument $dom = new DOMDocument(); // Enable validate on parse $dom->validateOnParse = true; // Create an element $element = $dom->createElementNS("my_namespace", "x:p", 'Hello, this is my paragraph.'); // Add the node to the dom $newnode = $dom->appendChild($element); // Set the attribute $newnode->setAttributeNS("my_namespace", "id", "my_value"); // Set that attribute as id $element->setIDAttributeNS("my_namespace", 'id', true); echo $dom->saveXML(); ?> Output: You can press Ctrl+U to see the DOM. Example 2: php <?php // Create a new DOMDocument $dom = new DOMDocument(); // Enable validate on parse $dom->validateOnParse = true; // Create an element $element = $dom->createElementNS("my_namespace", "x:p", 'GeeksforGeeks'); // Add the node to the dom $newnode = $dom->appendChild($element); // Set the attribute $newnode->setAttributeNS("my_namespace", "id", "geeksforgeeks"); // Set that attribute as id $element->setIDAttributeNS("my_namespace", 'id', true); // Get the text of element with id='geeksforgeeks' // just to see if it works $value = $dom->getElementById('geeksforgeeks')->textContent; echo $value; ?> Output: GeeksforGeeks Reference: https://www.php.net/manual/en/domelement.setidattributens.php Comment More infoAdvertise with us Next Article PHP | DOMElement setIdAttributeNS() Function G gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-DOM Similar Reads PHP | DOMElement setIdAttribute() Function The DOMElement::setIdAttribute() function is an inbuilt function in PHP which is used to declare the attribute specified by name to be of type ID. Syntax: void DOMElement::setIdAttribute( string $name, bool $isId ) Parameters: This function accepts two parameters as mentioned above and described bel 2 min read PHP | DOMElement setAttributeNS() Function The DOMElement::setAttributeNS() function is an inbuilt function in PHP which is used to set an attribute with given namespace and name to the given value. If the attribute does not exist, it will be created. Syntax: void DOMElement::setAttributeNS( string $namespaceURI, string $qualifiedName, strin 2 min read PHP | DOMElement setIdAttributeNode() Function The DOMElement::setIdAttributeNode() function is an inbuilt function in PHP which is used to declare the attribute specified by DOMAttr instance to be of type ID. Syntax: void DOMElement::setIdAttributeNode( DOMAttr $attr, bool $isId ) Parameters: This function accepts two parameters as mentioned ab 2 min read PHP | DOMElement setAttribute() Function The DOMElement::setAttribute() function is an inbuilt function in PHP which is used to set an attribute with given name to the given value. If the attribute does not exist, it will be created. Syntax: DOMAttr DOMElement::setAttribute( string $name, string $value ) Parameters: This function accepts t 2 min read PHP | DOMElement setAttributeNodeNS() Function The DOMElement::setAttributeNodeNS() function is an inbuilt function in PHP which is used to add a new attribute node to element. This is just an alternative for setAttributeNode() function. Syntax: DOMAttr DOMElement::setAttributeNodeNS( DOMAttr $attr ) Parameters: This function accepts a single p 2 min read Like