API16

API16:JXMLElement/getAttribute

From Joomla! Documentation

Description

LEGACY - Gets an elements attribute by name.



Syntax

getAttribute($name)
Parameter Name Default Value Description
$name $name

Returns

string

Defined in

libraries/joomla/utilities/xmlelement.php

Importing

jimport( 'joomla.utilities.xmlelement' );

Source Body

public function getAttribute($name)
{
        return (string)$this->attributes()->$name;
}



Examples

Code Examples

Get the attribute of an element

demo.xml

<jdoc>
	<doku kategory="Info">Wiki</doku>
</jdoc>
<?php

$xml = JFactory::getXML('demo.xml');

echo $xml->doku->getAttribute('kategory');

/* Better: */
echo $xml->doku->attributes()->kategory;

Output:

Info

Elkuku 11:16, 14 January 2011 (CST) Edit comment