Probleme avec script : XML to PHP

Hop
Invité n'ayant pas de compte PHPfrance

15 août 2005, 20:07

Salut à tous
j'utilise ce script pour afficher un flux XML en php :

Code : Tout sélectionner

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
Merci

Mammouth du PHP | 19672 Messages

15 août 2005, 22:23

Il est fort possible que le time-out de 30 seconde soit insuffisant pour traiter 40Mo d'un coup. As-tu un message d'erreur au moins ?
Codez en pensant que celui qui maintiendra votre code est un psychopathe qui connait votre adresse :axe:

jimenezf
Invité n'ayant pas de compte PHPfrance

18 nov. 2005, 12:46

Bonjour,

J'ai suivi votre discussion concernant XML, et je me demandais si vous aviez connaissance d'un exemple php qui ferait des transformation d'un formulaire vers un fichier XML et vice-versa

Ou une fonction du genre xml2form et form2xml

Si oui ca m'intéresse énormément.

Merci