PHP | DOMNamedNodeMap getNamedItemNS() function Last Updated : 19 Feb, 2020 Comments Improve Suggest changes Like Article Like Report The DOMNamedNodeMap::getNamedItemNS() function is an inbuilt function in PHP which is used to retrieve a node with a specific local name and namespace URI. This function can be used to get the value of a attribute from a specific namespace. Syntax: DOMNode DOMNamedNodeMap::getNamedItemNS ( string $namespaceURl, string $localName ) Parameters: This function accepts two parameters as mentioned above and described below: $namespaceURl: It specifies the namespace URI. $localName: It specifies the local name. Return Value: This function returns a node with given local name and namespace URI. Below given programs illustrate the DOMNamedNodeMap::getNamedItemNS() function in PHP: Program 1: In this example, we will get the attribute value of a element with two different namespaces. php <?php // Create a new DOMDocument $dom = new DOMDocument(); // Create an element with namespace $node = $dom->createElementNS( "my_namespace", "x:p", 'Hello, this is my paragraph.'); // Add the node to the dom $newnode = $dom->appendChild($node); // Set the attribute with a namespace $newnode->setAttributeNS("my_namespace", "style", "color:blue"); echo "<b>Attributes with my_namespace as namespace:</b> <br>"; // Get the attribute value $attribute = $node->attributes->getNamedItemNS('my_namespace', 'style')->nodeValue; echo $attribute; echo "<br><b>Attributes with other_namespace as namespace:</b> <br>"; // Get the attribute value $attribute = $node->attributes->getNamedItemNS('other_namespace', 'style')->nodeValue; echo $attribute; ?> Output: Attributes with my_namespace as namespace: color:blue Attributes with other_namespace as namespace: // Empty string means no attributes found. Program 2: In this example we will check if the function fetches the latest attribute values or not by altering the value of attribute. php <?php // Create a new DOMDocument $dom = new DOMDocument(); // Create an element $node = $dom->createElementNS("my_namespace", "x:p", 'GeeksforGeeks'); // Add the node to the dom $newnode = $dom->appendChild($node); // Set the attribute with a namespace $newnode->setAttributeNS("my_namespace", "style", "color:blue"); echo "<b>Before:</b> <br>"; // Get the attribute value $attribute = $node->attributes->getNamedItemNS('my_namespace', 'style')->nodeValue; echo $attribute; // Change the attribute value $newnode->setAttributeNS("my_namespace", "style", "color:red"); echo "<br><b>After:</b> <br>"; // Get the attribute value $attribute = $node->attributes->getNamedItemNS('my_namespace', 'style')->nodeValue; echo $attribute; ?> Output: Before: color:blue After: color:red Reference: https://www.php.net/manual/en/domnamednodemap.getnameditemns.php Comment More infoAdvertise with us Next Article PHP | DOMNamedNodeMap getNamedItemNS() function G gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP | DOMNamedNodeMap getNamedItem() Function The DOMNamedNodeMap::getNamedItem() function is an inbuilt function in PHP which is used to retrieve a node specified by name. This is used to get the attribute items and further get information about the attribute. Syntax: DOMNode DOMNamedNodeMap::getNamedItem( string $name ) Parameters: This funct 2 min read PHP | DOMNamedNodeMap item() function The DOMNamedNodeMap::item() function is an inbuilt function in PHP which is used to retrieve a node specified by index. This function is used to get a specific attribute from an element and further we can get the name or value of that attribute as per requirements. Syntax: DOMNamedNodeMap DOMNamedNo 2 min read PHP | DOMNode getLineNo() function The DOMNode::getLineNo() function is an inbuilt function in PHP which is used to get the line number for where the node is defined. Syntax: DOMNode DOMNode::getLineNo( void ) Parameters:This function doesnât accept any parameter. Return Value: This function returns the line number where the node was 2 min read PHP | DOMNamedNodeMap count() Function The DOMNamedNodeMap::count() function is an inbuilt function in PHP which is used to get the number of nodes in the map. It can be used to count attributes of a element. Syntax: int DOMNamedNodeMap::count( void ) Parameters: This function doesnât accepts any parameter. Return Value: This function re 2 min read PHP | DOMElement getAttributeNS() Function The DOMElement::getAttributeNS() function is an inbuilt function in PHP which is used to get the value of the attribute in a specific namespace with local name for the current node. Syntax: string DOMElement::getAttributeNS( string $namespaceURI, string $localName ) Parameters: This function accepts 2 min read Like