Basic example of use :
<?xml version="1.0" encoding="UTF-8"?>
<racine version="2.0a">
  <article/>
</racine>
<?php
(...)
 echo $doc->documentElement->attributes->getNamedItem("version")->nodeValue;
// returns "2.0a"
?>(PHP 5, PHP 7, PHP 8)
DOMNamedNodeMap::getNamedItem — Retourne un nœud spécifié par son nom
   Récupère un nœud spécifié par son nodeName.
  
qualifiedName
       Le nodeName du nœud à récupérer.
      
   Un nœud (de n'importe quel type) avec un nodeName spécifié, ou 
   null si aucun nœud n'est trouvé.
  
Exemple #1 Récupérer un attribut sur un nœud
<?php
$doc = new DOMDocument;
$doc->load('examples/book.xml');
$id = $doc->firstChild->nextSibling->nextSibling->firstChild->nextSibling->attributes->getNamedItem('id');
?>Exemple #2 Accéder un élément avec la syntaxe de tableau
<?php
$doc = new DOMDocument;
$doc->load('examples/book.xml');
$id = $doc->firstChild->nextSibling->nextSibling->firstChild->nextSibling->attributes['id'];
?>Basic example of use :
<?xml version="1.0" encoding="UTF-8"?>
<racine version="2.0a">
  <article/>
</racine>
<?php
(...)
 echo $doc->documentElement->attributes->getNamedItem("version")->nodeValue;
// returns "2.0a"
?>