Added check for DOMDocument existence