public function expand(DOMNode $basenode = null)
    {
        if (null === $basenode) {
            $basenode = new DomDocument();
        }

        if ($basenode instanceof DOMDocument) {
            $doc = $basenode;
        } else {
            $doc = $basenode->ownerDocument;
        }

        if (false === $node = $this->reader->expand($basenode)) {
            throw new BadMethodCallException('Unable to expand node.');
        }

        if ($node->ownerDocument !== $doc) {
            $node = $doc->importNode($node, true);
        }

        return $node;
    }