note 86471 modified in function.simplexml-load-file by danbrown
| From: | danbrown@php.net | Date: | Tue, 21 Oct 2008 14:03:56 +0000 |
| Subject: | note 86471 modified in function.simplexml-load-file by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-145538@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>
<?php
$filename = '...';
$xml = simplexml_load_file($filename);
$p_cnt = count($xml->param);
for($i = 0; $i < $p_cnt; $i++) {
$param = $xml->param[$i];
...;
}
?>
--was--
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];
...;
}
?>
http://php.net/manual/en/function.simplexml-load-file.php