public function setElement($document, $element = null)
    {
        if (empty($document)) {
            // Make sure we always have an element to query against which should not return any returns.
            $document = new DOMDocument();
            $document->loadXML('<dummy/>');
        }
        $this->document = $document;

        if (empty($element)) {
            $element = $this->document->documentElement;
        }
        $this->element = $element;
    }