note 98717 added to class.simplexmlelement

From: Date: Fri, 02 Jul 2010 11:28:12 +0000
Subject: note 98717 added to class.simplexmlelement
Groups: php.notes 
Request: Send a blank email to php-notes+get-170651@lists.php.net to get a copy of this message
Note that changing attributes from within a foreach loop, especially namespaced attributes, can be very tricky. For example, when trying to change the value of an existing xlink:href attribute: <?php foreach($xmlelement -> attributes('xlink', true) as $attribute => $attribvalue){ $attribvalue[0] = 'value'; // Throws an error $attribvalue = 'value'; // Does not change your XML $xmlelement -> addAttribute($attribute, 'value', 'http://www.w3.org/1999/xlink'); // Adds an attribute, does not change existing one. $xmlelement[$attribute] = 'value'; // Adds an attribute, does not change existing one. } ?> Instead, you should access the array returned by the attributes() function directly, like this: <?php $xmlelement -> attributes('xlink', true) -> href = 'value'; // Works! ?> ---- Server IP: 69.147.83.197 Probable Submitter: 81.204.184.127 ---- Manual Page -- http://www.php.net/manual/en/class.simplexmlelement.php Edit -- https://master.php.net/note/edit/98717 Del: integrated -- https://master.php.net/note/delete/98717/integrated Del: useless -- https://master.php.net/note/delete/98717/useless Del: bad code -- https://master.php.net/note/delete/98717/bad+code Del: spam -- https://master.php.net/note/delete/98717/spam Del: non-english -- https://master.php.net/note/delete/98717/non-english Del: in docs -- https://master.php.net/note/delete/98717/in+docs Del: other reasons-- https://master.php.net/note/delete/98717 Reject -- https://master.php.net/note/reject/98717 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#170651) next »