note 86471 added to function.simplexml-load-file

From: Date: Tue, 21 Oct 2008 10:34:47 +0000
Subject: note 86471 added to function.simplexml-load-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-145534@lists.php.net to get a copy of this message
In case you have a XML file with a series of equally named elements on one level simplexml incorrectly processes them and doesn't allow to walk through the array using foreach(). As far as I'm concerned, it is the problem caused by PHP xml_parser (see: http://ru2.php.net/manual/ru/function.xml-parser-create.php#53188). To avoid this, just use count() and walk through the array using for(). Example: <params> <param> <name>version.shell</name> <value>1.0</value> </param> <param> <name>version.core</name> <value>1.0</value> </param> <param> <name>file.lang</name> <value>vc.lang</value> </param> ... </params> <? $filename = '...'; $xml = simplexml_load_file($filename); $p_cnt = count($xml->param); for($i = 0; $i < $p_cnt; $i++) { $param = $xml->param[$i]; ...; } ?> ---- Server IP: 91.189.86.54 Probable Submitter: 82.114.107.226 (proxied: 82.114.107.226) ---- Manual Page -- http://www.php.net/manual/en/function.simplexml-load-file.php Edit -- https://master.php.net/note/edit/86471 Del: integrated -- https://master.php.net/note/delete/86471/integrated Del: useless -- https://master.php.net/note/delete/86471/useless Del: bad code -- https://master.php.net/note/delete/86471/bad+code Del: spam -- https://master.php.net/note/delete/86471/spam Del: non-english -- https://master.php.net/note/delete/86471/non-english Del: in docs -- https://master.php.net/note/delete/86471/in+docs Del: other reasons-- https://master.php.net/note/delete/86471 Reject -- https://master.php.net/note/reject/86471 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#145534) next »