Voting

: zero plus one?
(Example: nine)

The Note You're Voting On

mindpower
18 years ago
A simple extension that adds a method for retrieving a specific attribute:

<?php
class simple_xml_extended extends SimpleXMLElement
{
public function
Attribute($name)
{
foreach(
$this->Attributes() as $key=>$val)
{
if(
$key == $name)
return (string)
$val;
}
}

}

$xml = simplexml_load_string('
<xml>
<dog type="poodle" owner="Mrs Smith">Rover</dog>
</xml>'
, 'simple_xml_extended');

echo
$xml->dog->Attribute('type');

?>

outputs 'poodle'

I prefer to use this technique rather than typecasting attributes.

<< Back to user notes page

To Top