API16:JSimpleXMLElement/getElementByPath
From Joomla! Documentation
Description
Get an element in the document by / separated path
Syntax
getElementByPath($path)
| Parameter Name | Default Value | Description |
|---|---|---|
| $path | $path The / separated path to the element |
Returns
object
Defined in
libraries/joomla/utilities/simplexml.php
Importing
jimport( 'joomla.utilities.simplexml' );
Source Body
function getElementByPath($path)
{
$tmp = &$this;
$parts = explode('/', trim($path, '/'));
foreach ($parts as $node)
{
$found = false;
foreach ($tmp->_children as $child)
{
if (strtoupper($child->_name) == strtoupper($node))
{
$tmp = &$child;
$found = true;
break;
}
}
if (!$found) {
break;
}
}
if ($found) {
return $tmp;
}
return false;
}
Examples
Code Examples