public function addChild($name, $value=null, $namespace=null)
    {
        $esc_val = utf8_encode(htmlentities($value, ENT_QUOTES, 'UTF-8', false));
        if ($value == $esc_val)
            return parent::addChild($name, $esc_val, $namespace);
        else {
            $xml_field = parent::addChild($name, '', $namespace);
            $xml_field->addCData($esc_val);
            $xml_field->addAttribute('isCDATA', true);

            return $xml_field;
        }
    }
public function addChild($name, $value=null, $namespace=null)
    {
        $esc_val = utf8_encode(htmlentities($value, ENT_QUOTES, 'UTF-8', false));
        if ($value == $esc_val)
            return parent::addChild($name, $esc_val, $namespace);
        else {
            $xml_field = parent::addChild($name, '', $namespace);
            $xml_field->addCData($esc_val);
            $xml_field->addAttribute('isCDATA', true);

            return $xml_field;
        }
    }
public function addChild ( $ name , $ value = null , $ namespace = null ) { $ esc_val = utf8_encode ( htmlentities ( $ value , ENT_QUOTES , 'UTF-8' , false ) ) ; if ( $ value == $ esc_val ) return parent :: addChild ( $ name , $ esc_val , $ namespace ) ; else { $ xml_field = parent :: addChild ( $ name , '' , $ namespace ) ; $ xml_field -> addCData ( $ esc_val ) ; $ xml_field -> addAttribute ( 'isCDATA' , true ) ; return $ xml_field ; } }
Adds a child to the current element, but with automatic CDATA support.

@param string $name      The name of the child element to add
@param string $value     The value of the child element
@param string $namespace If specified, use this namespace

@return SimpleXMLElement a SimpleXMLElement object representing the child added to the XML node.
Adds a child to the current element but with automatic CDATA support .