Wykorzystuję tą funkcję w ten sposób:
<?php function XMLToArray( $Iterator ) { while ( $Iterator->valid() ) { if ( $Iterator->hasChildren() === true ) { $array[ $Iterator->key() ] = XMLToArray( $Iterator->getChildren() ); $Iterator->next(); } else { { $_key = $Iterator->key(); $_value = $Iterator->current(); $Iterator->next(); if ( $Iterator->key() == $_key ) { } else { $array[ $_key ] = (string)$_value; } } else { $array[ $Iterator->key() ][] = (string)$Iterator->current(); $Iterator->next(); } } } return $array; } ?>
A oto przykładowy plik XML (dcc.xml), który parsuje:
<?php $Iterator->rewind(); printArray( XMLToArray( $Iterator ) ); ?>
Po uruchomieniu funkcji otrzymuję niepełny wynik:
<?xml version="1.0" encoding="iso-8859-2" ?> <domaincheckerconfiguration> <language>pl</language> <allowdomains> <domain>pl</domain> <domain>net.pl</domain> <domain>com.pl</domain> <domain>com</domain> <domain>net</domain> </allowdomains> </domaincheckerconfiguration>
Kod
Array
(
[language] => pl
[allowdomains] => Array
(
)
)
A powinien być taki:(
[language] => pl
[allowdomains] => Array
(
)
)
Kod
Array
(
[language] => pl
[allowdomains] => Array
(
[0] => pl
[1] => net.pl
[2] => com.pl
[3] => com
[4] => net
)
)
Po drugim zagłębieniu (root->allowdomains) metoda SimpleXMLIterator::valid zwraca FALSE - nie wiem dlaczego (
[language] => pl
[allowdomains] => Array
(
[0] => pl
[1] => net.pl
[2] => com.pl
[3] => com
[4] => net
)
)

Prosiłbym o pomoc
