public function setContent($content, $type = 'text')
    {
        $type = (string) $type;
        $this->setType($type);
        $document = $this->getDomElement()->ownerDocument;

        if ('text' === $type || 'html' === $type) {
            $this->getDomElement()->nodeValue = (string) $content;
        } elseif ('xhtml' === $type) {
            if (!$content instanceof \DOMElement) {
                throw new \InvalidArgumentException('Content should be an instance of DOMElement');
            }
            Xhtml::import($content, $this->getDomElement());
        } elseif ($this->isXmlMimeType($type)) {
            if (!$content instanceof \DOMElement) {
                throw new \InvalidArgumentException('Content should be an instance of DOMElement');
            }
            $this->getDomElement()->appendChild($document->importNode($content, true));
        } elseif (stripos($type, 'text/') === 0) {
            $this->getDomElement()->nodeValue = (string) $content;
        } else {
            $this->getDomElement()->nodeValue = base64_encode($content);
        }
        $this->setCachedProperty('content', $content);
    }