public function elem($name, $attrib = [], $content = null, $endTag = true)
    {
        $namespace = null;
        if (isset($attrib['namespace'])) {
            $namespace = $attrib['namespace'];
            unset($attrib['namespace']);
        }
        $cdata = false;
        if (is_array($content) && isset($content['cdata'])) {
            $cdata = true;
            unset($content['cdata']);
        }
        if (is_array($content) && array_key_exists('value', $content)) {
            $content = $content['value'];
        }
        $children = [];
        if (is_array($content)) {
            $children = $content;
            $content = null;
        }

        $xml = '<' . $name;
        if (!empty($namespace)) {
            $xml .= ' xmlns';
            if (is_array($namespace)) {
                $xml .= ':' . $namespace['prefix'];
                $namespace = $namespace['url'];
            }
            $xml .= '="' . $namespace . '"';
        }
        $bareName = $name;
        if (strpos($name, ':') !== false) {
            list($prefix, $bareName) = explode(':', $name, 2);
            switch ($prefix) {
                case 'atom':
                    $xml .= ' xmlns:atom="http://www.w3.org/2005/Atom"';
                    break;
            }
        }
        if ($cdata && !empty($content)) {
            $content = '<![CDATA[' . $content . ']]>';
        }
        $xml .= '>' . $content . '</' . $name . '>';
        $elem = Xml::build($xml, ['return' => 'domdocument']);
        $nodes = $elem->getElementsByTagName($bareName);
        if ($attrib) {
            foreach ($attrib as $key => $value) {
                $nodes->item(0)->setAttribute($key, $value);
            }
        }
        foreach ($children as $child) {
            $child = $elem->createElement($name, $child);
            $nodes->item(0)->appendChild($child);
        }

        $xml = $elem->saveXml();
        $xml = trim(substr($xml, strpos($xml, '?>') + 2));

        return $xml;
    }