(PHP 5, PHP 7)
DOMDocument::getElementById — Busca un elemento con cierto id
Esta función es similar a DOMDocument::getElementsByTagNamepero busca un elemento con el id dado.
Para que esta función trabaje, necesitará asignar algunos atributos ID con DOMElement::setIdAttribute o un DTD que defina un atributo de tipo ID. En el último caso necesitará validar el documento con DOMDocument::validate o DOMDocument::$validateOnParse antes de utilizar esta función.
elementIdEl valor de id único para un elemento.
   Devuelve el DOMElement o NULL si el elemento no ha sido encontrado. 
  
Ejemplo #1 Ejemplo de DOMDocument::getElementById()
Los siguientes ejemplos usan book.xml, cuyo contenido es el siguiente:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE books [
  <!ELEMENT books   (book+)>
  <!ELEMENT book    (title, author+, xhtml:blurb?)>
  <!ELEMENT title   (#PCDATA)>
  <!ELEMENT blurb   (#PCDATA)>
  <!ELEMENT author  (#PCDATA)>
  <!ATTLIST books   xmlns        CDATA  #IMPLIED>
  <!ATTLIST books   xmlns:xhtml  CDATA  #IMPLIED>
  <!ATTLIST book    id           ID     #IMPLIED>
  <!ATTLIST author  email        CDATA  #IMPLIED>
]>
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<books xmlns="http://books.php/" xmlns:xhtml="http://www.w3.org/1999/xhtml">
  <book id="php-basics">
    <title>PHP Basics</title>
    <author email="jim.smith@basics.php">Jim Smith</author>
    <author email="jane.smith@basics.php">Jane Smith</author>
    <xhtml:blurb><![CDATA[
<p><em>PHP Basics</em> provides an introduction to PHP.</p>
]]></xhtml:blurb>
  </book>
  <book id="php-advanced">
    <title>PHP Advanced Programming</title>
    <author email="jon.doe@advanced.php">Jon Doe</author>
  </book>
</books>
<?php
$doc = new DomDocument;
// Necesitamos validar nuestro documento antes de referirnos al id
$doc->validateOnParse = true;
$doc->Load('book.xml');
echo "The element whose id is 'php-basics' is: " . $doc->getElementById('php-basics')->tagName . "\n";
?>
El resultado del ejemplo sería:
The element whose id is 'php-basics' is: book