Précédent   Forum des professionnels en informatique > PHP > Bibliothèques et frameworks > XML
XML Forum d'entraide sur XML avec PHP. Exemples : SimpleXML, OpenXML... Avant de poster -> FAQ XML, Cours XML et Sources XML
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 08/06/2008, 12h35   #1
Invité de passage
 
Inscription : avril 2008
Messages : 4
Détails du profil
Informations forums :
Inscription : avril 2008
Messages : 4
Points : 0
Points : 0
Par défaut Problème avec le parser SAX

Bonjour,

Je résume vite fait mon problème. J'ai une feuille xml avec différentes données à insérer dans différents champs d'une meme table dans une base de données. J'utilise donc un parser SAX. A l'exécution, j'ai des erreurs de ce type :
Warning: xml_parse() [function.xml-parse]: Unable to call handler starElement() in C:\wamp\www\dubois\ParserLocalisation3.php on line 91

Warning: xml_parse() [function.xml-parse]: Unable to call handler xml_result() in C:\wamp\www\dubois\ParserLocalisation3.php on line 91

Voici le fichier PHP en question :

Code :
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
 
$connexion = mysql_connect("localhost", "root", "") or die("connexion impossible") ;
$db = mysql_select_db("dubois", $connexion) or die("selection impossible") ;
echo "test...";
 
class tag
{
    var $chemin="";
    var $chapitre;
    var $localisation;
    var $para_section;
    var $para_soussection;
       var $paragraphe;
    #var $tab_localisation=array(); #recuperer le contenu dans un tableau pour que ce soit plus propre
 
 
#création du parser
 
    function startElement($sax, $nom, $attributs)
    {
        var_dump($sax, $nom, $attributs);
        $this->chemin .="/".$nom;
        if ($this->chemin=="html/body")
        {
            $this->chapitre = "";
            $this->localisation = "";
            $this->para_section = "";
            $this->para_soussection = "";
            $this->paragraphe = "";
        }
    }
 
    function endElement($sax, $nom)
    {
        if ($this->chemin=="body")
        {
            $chapitre = ($this->chapitre);
            $localisation = ($this->localisation);
            $para_section = ($this->para_section);
            $para_soussection = ($this->para_soussection);
            $para_paragraphe = ($this->para_paragraphe);
        }
        $pos = strpos($this->chemin, "/");
        $this->chemin = substr ($this->chemin, 0, $pos);
    }
 
    function texte ($sax, $texte)
    {
        if ($this->chemin=="/chapitre")
        {
            $this->chapitre .=$texte;
            $req="INSERT INTO localisation( Chapitre )
            VALUES ('$this->chapitre')";
            error_reporting();        
            $res = mysql_query($req);
        }
        elseif ($this->chemin=="/body/localisation")
        {
        $this->localisation .=$texte;
        }
        elseif ($this->chemin=="/body/localisation/para_section")
        {
        $this->para_section .=$texte;
        }
        elseif ($this->chemin=="/body/localisation/para_soussection")
        {
        $this->para_soussection .=$texte;
        }
        elseif ($this->chemin=="/body/localisation/para_paragraphe")
        {
        $this->para_paragraphe .=$texte;
        }
    }
}
    function xml_result()
    {
    global $tag;
    $tag = new tag();
 
    #$tab=$xml->tab_localisation;
    $sax=xml_parser_create("UTF-8");
    xml_set_object ($sax, $tag);
    xml_parser_set_option ($sax, XML_OPTION_CASE_FOLDING, FALSE);
    xml_set_character_data_handler ($sax, "xml_result");
    xml_set_element_handler ($sax, "starElement", "endElement");
    $fichier = "localisation1-xml.xml";
    $fp = fopen($fichier, "r");
        while ($xml = fread ($fp, 1024))
        {
            if (!xml_parse($sax, $xml, true))
            {
                printf("Erreur XML : %s à la ligne %d lors du traitement de l'entité %s\n",
                xml_error_string($sax),
                xml_get_current_line_number($sax),
                xml_get_error_code ($sax),
                $openEntityNames);
                xml_parser_free($sax);
 
                return FALSE;
            }
 
        xml_parse ($sax, $xml, feof($fp));
        }
    }
    /*function requete()
    {
#Faire une condition par ex si la balise ouvrante est chapitre alors :
        $req="INSERT INTO localisation( Chapitre )
        VALUES ('$this->chapitre')";
        error_reporting();        
        $res = mysql_query($req);
        $db->debug();
 
    }*/
 
xml_result();
 
#requete();
 
echo "...test";
 
?>

J'ai des connaissances de base en PHP donc il se peut que l'erreur soit un oubli d'appel de fonction ou une mauvaise utilisation. Pourtant dans mon entourage, personne n'a pas m'aider.

Quelqu'un pourrait me dire d'où vient mon erreur ?? Merci
carmensam est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/08/2009, 16h50   #2
Invité de passage
 
Inscription : octobre 2006
Messages : 1
Détails du profil
Informations forums :
Inscription : octobre 2006
Messages : 1
Points : 1
Points : 1
Par défaut créer un parseur SAX qui permet de parcourir un fichier xml et l'enregistrer dans une base de données MYSQL. a

Bonjour

As tu trouvé une solution à ton problème? si ou c'est besoin de ton code pour demarrer. Je veux créer un parseur SAX qui permet de parcourir un fichier xml et l'enregistrer dans une base de données MYSQL. avec PHP
djomapyr est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 02h11.


 
 
 
 
Partenaires

Hébergement Web