FeedWriter\Feed::makeNode PHP Method

makeNode() private method

Creates a single node in XML format
private makeNode ( string $tagName, mixed $tagContent, array $attributes = null, boolean $omitEndTag = false ) : string
$tagName string name of the tag
$tagContent mixed tag value as string or array of nested tags in 'tagName' => 'tagValue' format
$attributes array Attributes (if any) in 'attrName' => 'attrValue' format
$omitEndTag boolean True if the end tag should be omitted. Defaults to false.
return string formatted xml tag
    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;
    }