note 72697 added to function.simplexml-load-string

From: Date: Tue, 30 Jan 2007 11:03:43 +0000
Subject: note 72697 added to function.simplexml-load-string
Groups: php.notes 
Request: Send a blank email to php-notes+get-122346@lists.php.net to get a copy of this message
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. ---- Server IP: 83.138.144.80 Probable Submitter: 86.3.95.82 ---- Manual Page -- http://www.php.net/manual/en/function.simplexml-load-string.php Edit -- https://master.php.net/note/edit/72697 Del: integrated -- https://master.php.net/note/delete/72697/integrated Del: useless -- https://master.php.net/note/delete/72697/useless Del: bad code -- https://master.php.net/note/delete/72697/bad+code Del: spam -- https://master.php.net/note/delete/72697/spam Del: non-english -- https://master.php.net/note/delete/72697/non-english Del: in docs -- https://master.php.net/note/delete/72697/in+docs Del: other reasons-- https://master.php.net/note/delete/72697 Reject -- https://master.php.net/note/reject/72697 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#122346) next »