Optimize ID attribute search, if the DOM implementation has indexed it
There are a few gotchas in DOMDocument#getElementById() (see T215000
for discussion) so be extra careful and double-check the result.
Change-Id: Ie7dc1c969543136a8e4b48a2afa7c9e198938493