Bonjour,
Voici mon code:
et mon petit fichier xml :
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 <?php set_time_limit(0); $fichier = "koko.xml"; function fonctionBaliseOuvrante($parseur, $nomBalise,$attribut) { global $dbr; $dbr = $nomBalise;} function fonctionBaliseFermante($parseur, $nomBalise){ global $dbr,$a,$b,$c; $a="0"; while ($nomBalise!="Concept"){ if($nomBalise=="ATTRIBUTE_REF"){ $a=$a+1; echo $a; } $dbr= "";} } function fonctionTexte($parseur, $text){ global $dbr,$AR,$ei,$i,$j,$k,$demo,$medoc,$d,$e,$y,$z; $z=0;$e=0;$f=""; if (substr($text, 0, 2)=="1-"){ $i=$text; $z=$z+1; } if (substr($text, 0, 2)=="2-"){ $j=$text;} if (substr($text, 0, 2)=="3-"){ $k=$text;} } $parseurXML = xml_parser_create(); xml_set_element_handler($parseurXML, "fonctionBaliseOuvrante", "fonctionBaliseFermante"); xml_set_character_data_handler($parseurXML, "fonctionTexte"); // Ouverture du fichier $fp = fopen($fichier, "r"); if (!$fp) die("Impossible d'ouvrir le fichier XML"); while ( $ligneXML =fread($fp,50)){ xml_parse($parseurXML, $ligneXML, feof($fp)) or die("Erreur XML"); } fclose($fp); xml_parser_free($parseurXML); ?>
J'arrive à parcourir mon fichier xml mais par exemple si je veux compter combien de fois il passe sur la balise "Concept_Ref" avant qu'il atteigne la balise fermante"concept". Il ne m'affiche pas 11 mais "11111111111" . Comment faut il faire pour obtenir le nombre 11. Car ceci n'est qu'un bout de mon code car j'aimerais rentrer plusieurs concepts dans une base de données.
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 <c> <Concept> <ID> 12866 </ID> <Extent> <Object_Ref>PB0300298</Object_Ref> </Extent> <Intent> <Attribute_Ref>1-PRURIT</Attribute_Ref> <Attribute_Ref>3-60_</Attribute_Ref> <Attribute_Ref>1-CONJONCTIVITE</Attribute_Ref> <Attribute_Ref>1-OEDEME DE LA FACE</Attribute_Ref> <Attribute_Ref>1-OEDEME BUCCAL</Attribute_Ref> <Attribute_Ref>3-F</Attribute_Ref> <Attribute_Ref>1-ERUPTION</Attribute_Ref> <Attribute_Ref>2-DORZOLAMIDE</Attribute_Ref> <Attribute_Ref>2-TIMOLOL (MALEATE DE)</Attribute_Ref> </Intent> <Stability> 0.5</Stability> <PRRWithDemo> Infinity</PRRWithDemo> <PRRWithoutDemo> </PRRWithoutDemo> <Chi2> 178.24965035033622</Chi2> <UpperCovers> <Concept_Ref>6906</Concept_Ref> <Concept_Ref>8452</Concept_Ref> <Concept_Ref>4613</Concept_Ref> <Concept_Ref>3406</Concept_Ref> <Concept_Ref>9910</Concept_Ref> <Concept_Ref>5601</Concept_Ref> <Concept_Ref>5673</Concept_Ref> <Concept_Ref>4459</Concept_Ref> <Concept_Ref>8858</Concept_Ref> <Concept_Ref>6236</Concept_Ref> <Concept_Ref>3034</Concept_Ref> </UpperCovers> </Concept> </c>
Pouvez-vous m'aider??
Merci
Partager