Using DOM implementations like that quickly gets bloated and hard to debug, not to mention performance overhead from the DOM itself (e.g. PHP).
Personally, I tried working with HTML like that in PHP with a class that parsed HTML files into a hierarchical array which could be manipulated like:
$var['html']['body']['p']['strong'] = 'etc';
With support for attributes and CDATA and everything but no matter how seductive it may be from a programmer's point of view, it's always just more trouble than it's worth to work like that.
(I ended up just using that xml2array/array2xml crap to create XML trees for XSLT)