protected function getElementByIdValue($document, $tag, $value) { //hack to allow upper case and lower case attribute names. foreach (array('id', 'ID', 'Id', 'iD') as $id) { $xpath = "//{$tag}[@{$id}='{$value}']"; foreach ($document->xpath($xpath) as $node) { return $node; } } }