private function makeNode($tagName, $tagContent, array $attributes = null, $omitEndTag = false)
    {
        $nodeText = '';
        $attrText = '';

        if ($attributes != null) {
            foreach ($attributes as $key => $value) {
                $value = self::filterInvalidXMLChars($value);
                $value = htmlspecialchars($value);
                $attrText .= " $key=\"$value\"";
            }
        }

        $attrText .= (in_array($tagName, $this->CDATAEncoding) && $this->version == Feed::ATOM) ? ' type="html"' : '';
        $nodeText .= "<{$tagName}{$attrText}>";
        $nodeText .= (in_array($tagName, $this->CDATAEncoding)) ? '<![CDATA[' : '';

        if (is_array($tagContent)) {
            foreach ($tagContent as $key => $value) {
                if (is_array($value)) {
                    $nodeText .= PHP_EOL;
                    foreach ($value as $subValue) {
                        $nodeText .= $this->makeNode($key, $subValue);
                    }
                } else if (is_string($value)) {
                    $nodeText .= $this->makeNode($key, $value);
                } else {
                    throw new \InvalidArgumentException("Unknown node-value type for $key");
                }
            }
        } else {
            $tagContent = self::filterInvalidXMLChars($tagContent);
            $nodeText .= (in_array($tagName, $this->CDATAEncoding)) ? $this->sanitizeCDATA($tagContent) : htmlspecialchars($tagContent);
        }

        $nodeText .= (in_array($tagName, $this->CDATAEncoding)) ? ']]>' : '';

        if (!$omitEndTag)
            $nodeText .= "</$tagName>";

        $nodeText .= PHP_EOL;

        return $nodeText;
    }