More DomDocument fixes and sanity checks.