src/SimpleDOM.php
public function setNode($strName, $varValue = null)
    {
        if (!isset($this->children()->$strName)) {
            if ($varValue === null) {
                return $this->addChild($strName);
            } else {
                return $this->addChild($strName, $varValue);
            }
        } else {
            if ($varValue === null) {
                unset($this->children()->$strName);
                return null;
            } else {
                $this->children()->$strName = (string)$varValue;
                return $this->children()->$strName;
            }
        }
    }
public function setNode($strName, $varValue = null)
    {
        if (!isset($this->children()->$strName)) {
            if ($varValue === null) {
                return $this->addChild($strName);
            } else {
                return $this->addChild($strName, $varValue);
            }
        } else {
            if ($varValue === null) {
                unset($this->children()->$strName);
                return null;
            } else {
                $this->children()->$strName = (string)$varValue;
                return $this->children()->$strName;
            }
        }
    }
Set (or create) Node

@param string $strName
@param string $varValue
@return null|\static|\static[]