API15:JSimpleXMLElement/addChild
From Joomla! Documentation
Description
Adds a direct child to the element
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
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;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
Code Examples