JSimpleXMLElement/addChild
From Joomla! Documentation
< 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[edit]
Adds a direct child to the element
Syntax[edit]
addChild($name, $attrs=array(), $level=null)
Parameter Name | Default Value | Description |
---|---|---|
$name | $name | |
$attrs | array() | $attrs |
$level | null | $level |
Returns[edit]
The added child object
Defined in[edit]
libraries/joomla/utilities/simplexml.php
Importing[edit]
jimport( 'joomla.utilities.simplexml' );
Source Body[edit]
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[edit]
Code Examples[edit]