nycius Ich liebe dich ! | Salut
j'utilise ce script pour afficher un flux XML en php :
Code :
- function GetXMLTree ($xmldata)
- {
- ini_set ('track_errors', '0');
- $xmlreaderror = false;
- $parser = xml_parser_create ('ISO-8859-1');
- xml_parser_set_option ($parser, XML_OPTION_SKIP_WHITE, 1);
- xml_parser_set_option ($parser, XML_OPTION_CASE_FOLDING, 0);
- if (!xml_parse_into_struct ($parser, $xmldata, $vals, $index)) {
- $xmlreaderror = true;
- echo "error";
- }
- xml_parser_free ($parser);
- if (!$xmlreaderror) {
- $result = array ();
- $i = 0;
- if (isset ($vals [$i]['attributes']))
- foreach (array_keys ($vals [$i]['attributes']) as $attkey)
- $attributes [$attkey] = $vals [$i]['attributes'][$attkey];
- $result [$vals [$i]['tag']] = array_merge ($attributes, GetChildren ($vals, $i, 'open'));
- }
- ini_set ('track_errors', '0');
- return $result;
- }
- function GetChildren ($vals, &$i, $type)
- {
- if ($type == 'complete') {
- if (isset ($vals [$i]['value']))
- return ($vals [$i]['value']);
- else
- return '';
- }
- $children = array ();
- while ($vals [++$i]['type'] != 'close') {
- $type = $vals [$i]['type'];
- if (isset ($children [$vals [$i]['tag']])) {
- if (is_array ($children [$vals [$i]['tag']])) {
- $temp = array_keys ($children [$vals [$i]['tag']]);
- if (is_string ($temp [0])) {
- $a = $children [$vals [$i]['tag']];
- unset ($children [$vals [$i]['tag']]);
- $children [$vals [$i]['tag']][0] = $a;
- }
- } else {
- $a = $children [$vals [$i]['tag']];
- unset ($children [$vals [$i]['tag']]);
- $children [$vals [$i]['tag']][0] = $a;
- }
- $children [$vals [$i]['tag']][] = GetChildren ($vals, $i, $type);
- } else
- $children [$vals [$i]['tag']] = GetChildren ($vals, $i, $type);
- if (isset ($vals [$i]['attributes'])) {
- $attributes = array ();
- foreach (array_keys ($vals [$i]['attributes']) as $attkey)
- $attributes [$attkey] = $vals [$i]['attributes'][$attkey];
- if (isset ($children [$vals [$i]['tag']])) {
- if ($children [$vals [$i]['tag']] == '') {
- unset ($children [$vals [$i]['tag']]);
- $children [$vals [$i]['tag']] = $attributes;
- }
- elseif (is_array ($children [$vals [$i]['tag']])) {
- $index = count ($children [$vals [$i]['tag']]) - 1;
- if ($children [$vals [$i]['tag']][$index] == '') {
- unset ($children [$vals [$i]['tag']][$index]);
- $children [$vals [$i]['tag']][$index] = $attributes;
- }
- $children [$vals [$i]['tag']][$index] = array_merge ($children [$vals [$i]['tag']][$index], $attributes);
- } else {
- $value = $children [$vals [$i]['tag']];
- unset ($children [$vals [$i]['tag']]);
- $children [$vals [$i]['tag']]['value'] = $value;
- $children [$vals [$i]['tag']] = array_merge ($children [$vals [$i]['tag']], $attributes);
- }
- } else
- $children [$vals [$i]['tag']] = $attributes;
- }
- }
- return $children;
- }
- // URL du flux xml
- $url = "info.xml";
- $contents = file_get_contents($url);
- $data = GetXMLTree ($contents);
- print_r($data);
|
Celui ci marche sans probleme quand le fichier est pas trop gros
seulement si mon fichier XML fait 40mo ca ne marche pas
je lance le script mais rien; page blanche
si qqun peut m'aider |