Actions

API16

JSimpleXMLElement/addChild

< API16:JSimpleXMLElement

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description

Adds a direct child to the element



Syntax

addChild($name, $attrs=array(), $level=null)
Parameter Name Default Value Description
$name $name
$attrs array() $attrs
$level null $level

Returns

The added child object 

Defined in

libraries/joomla/utilities/simplexml.php

Importing

jimport( 'joomla.utilities.simplexml' );

Source Body

function addChild($name, $attrs = array(), $level = null)
{
        //If there is no array already set for the tag name being added,
        //create an empty array for it
        if (!isset($this->$name)) {
                $this->$name = array();
        }
 
        // set the level if not already specified
        if ($level == null)     {
                $level = ($this->_level + 1);
        }
 
        //Create the child object itself
        $classname = get_class($this);
        $child = new $classname($name, $attrs, $level);
 
        //Add the reference of it to the end of an array member named for the elements name
        $this->{$name}[] = &$child;
 
        //Add the reference to the children array member
        $this->_children[] = &$child;
 
        //return the new child
        return $child;
}



Examples

Code Examples


Advertisement