API15

API15:JSimpleXMLElement/getElementByPath

From Joomla! Documentation

Revision as of 22:25, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Get an element in the document by / separated path <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JSimpleXMLElement/getElementByPa...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Description

Get an element in the document by / separated path

[Edit Descripton]

Template:Description:JSimpleXMLElement/getElementByPath

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;
        $false  = false;
        $parts  = explode('/', trim($path, '/'));

        foreach ($parts as $node)
        {
                $found = false;
                foreach ($tmp->_children as $child)
                {
                        if ($child->_name == $node)
                        {
                                $tmp =& $child;
                                $found = true;
                                break;
                        }
                }
                if (!$found) {
                        break;
                }
        }

        if ($found) {
                $ref =& $tmp;
        } else {
                $ref =& $false;
        }
        return $ref;
}

[Edit See Also] Template:SeeAlso:JSimpleXMLElement/getElementByPath

Examples

<CodeExamplesForm />