Bonjour ,
J'ai actuellement un problème qui me triture depuis 2 jours .
Sur une machine j'ai un script qui me crée un fichier xml afin d'avoir une liste de tout les fichiers présent dans certains dossier.
Globalement le code php me ponds ce document xml la
Avec ce doc.xml je génère un tableau .
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36<?xml version="1.0" encoding="UTF-8"?> <content> <track> <id>1</id> <nom>Black_Seven-Spot radio_V2-25.mp3</nom> <type>spot</type> <genre>autre</genre> <by_for>Black_Seven</by_for> <duree>25</duree> </track> <track> <id>2</id> <nom>ZI-KA-35.mp3</nom> <type>habillage</type> <genre>autre</genre> <by_for>ZI</by_for> <duree>35</duree> </track> <track> <id>3</id> <nom>SMERAG-Spot_Radio_Juin_2017_GP-23.mp3</nom> <type>musique</type> <genre>hit</genre> <by_for>SMERAG</by_for> <duree>23</duree> </track> <track> <id>4</id> <nom>testclient-testprojet-25.mp3</nom> <type>musique</type> <genre>recurrent</genre> <by_for>testclient</by_for> <duree>25</duree> </track> </content>
Le code fonctionne correctement le tableau est convenablement remplis . Mais j'ai en retour cette erreur .
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 function tab_xml($commentaire) { if (file_exists(DIR_CONTENT)) { $xml=simplexml_load_file(DIR_CONTENT); $tab_xml['spot']=0; $tab_xml['habillage']=0; $tab_xml['hit']=0; $tab_xml['gold']=0; $tab_xml['recurrent']=0; $i=0; foreach ($xml->track as $track) { $tab_xml[$i]['nom']=$track->nom; $tab_xml[$i]['type']=$track->type; $tab_xml[$i]['genre']=$track->genre; $tab_xml[$i]['duree']=$track->duree; $tab_xml[$i]['jouer']=0; if ($track->type=="spot") { $tab_xml['spot']=$tab_xml['spot']+1; } elseif ($track->type=="habillage") { $tab_xml['habillage']=$tab_xml['habillage']+1; } elseif ($track->type=="musique") { if ($track->genre=="hit") { $tab_xml['hit']=$tab_xml['hit']+1; } elseif ($track->genre=="gold") { $tab_xml['gold']=$tab_xml['gold']+1; } elseif ($track->genre=="recurrent") { $tab_xml['recurrent']=$tab_xml['recurrent']+1; } } $i=$i+1; } if ($commentaire!="//") { foreach ($tab_xml as $key => $value) { if (!is_array($value)) { echo "$key : $value; <br />\n"; } else { echo "<br/>\n"; echo "Ligne : $key ; <br />\n"; foreach ($value as $key_ina => $value_ina) { echo "$key_ina : $value_ina;<br/>\n"; } } } echo "<br/><br/>\n"; } $_SESSION['tab_xml']=$tab_xml; } }
"Fatal error: Uncaught exception 'Exception' with message 'Serialization of 'SimpleXMLElement' is not allowed' in [no active file]:0 Stack trace: #0 {main} thrown in [no active file] on line 0"
Donc j'ai vérifier la création du xlm , il correctement parser.Il se trouve que "Fatal error:" disparait quand je commente les ligne qui accéde au nœud :
$tab_xml[$i]['nom']=$track->nom;
$tab_xml[$i]['type']=$track->type;
$tab_xml[$i]['genre']=$track->genre;
$tab_xml[$i]['duree']=$track->duree;
Ce n'est pas un bug bloquant mais ce n'est pas propre de le laisser trainer . De plus j'ai constater qu'il remonte a la fin de l’exécution des lignes .
Si vous avez une idée des question ou encore mieux une solution je suis dispo. Merci d'avance .
Edit : D'habitude je tape sur mes fichier xml de cette façon et j'ai jamais eu besoin de caught des exceptions.
Partager