DOMNamedNodeMap::getNamedItem
PHP function
Edit on GitHub ✎
(PHP 5, PHP 7, PHP 8)
Retrieves a node specified by name
Description
DOMNamedNodeMap::getNamedItem(string $qualifiedName): DOMNode|null
Retrieves a node specified by its nodeName.
Parameters
qualifiedNameThe
nodeNameof the node to retrieve.
Return Values
A node (of any type) with the specified nodeName, or null if no node is found.
Examples
Getting an attribute on a node
php
<?php
$doc = new DOMDocument;
$doc->load('examples/book.xml');
$id = $doc->firstChild->nextSibling->nextSibling->firstChild->nextSibling->attributes->getNamedItem('id');
?>Accessing attribute with array syntax
php
<?php
$doc = new DOMDocument;
$doc->load('examples/book.xml');
$id = $doc->firstChild->nextSibling->nextSibling->firstChild->nextSibling->attributes['id'];
?>See Also
DOMNamedNodeMap::getNamedItemNS