Commit live hack: pass XML_PARSE_HUGE (code uses 1 << 19 because the constant isn't available for some reason) into DOMDocument::loadXML() if the first call to loadXML() failed. This prevents newer versions of libxml2 from throwing a warning and messing up when the XML contains structures that are nested more than 256 levels deep. RELEASE-NOTES added to the 1.18 file, tagging this for backporting to 1.18 too.
We at Wikimedia never noticed this issue until we upgraded libxml2 on one of our servers as part of an OS upgrade, but apparently the interwebs knew about this since at least May 2010. Hat tip
to http://deriksmith.livejournal.com/57617.html , where I found this fix.