hasAttribute($attr)) { $ids = preg_split('/\s+/', trim($element->getAttribute($attr))); if ($ids === false) { continue; } $doc = $element->ownerDocument; if (!$doc) { continue; } foreach ($ids as $id) { if ($id === '') { continue; } $target = $doc->getElementById($id); if (!$target) { // XPath fallback in case DOMDocument getElementById fails (which is common without DTD/XML schemas) $xpath = new \DOMXPath($doc); $query = $xpath->query("//*[@id='" . addslashes($id) . "']"); if ($query === false || $query->length === 0) { return $this->createViolation( $element, "The attribute $attr refers to a non-existent ID: \"$id\".", "Ensure the element referenced by ID \"$id\" exists in the document, or correct the ID spelling." ); } } } } } return null; } }