Actions

API15

JSimpleXMLElement/addChild

From Joomla! Documentation

< API15:JSimpleXMLElement
Revision as of 17:25, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Adds a direct child to the element

[Edit Descripton]

Description:JSimpleXMLElement/addChild

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;
}

[Edit See Also] SeeAlso:JSimpleXMLElement/addChild

Examples

<CodeExamplesForm />