IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques et frameworks PHP Discussion :

[XML] Problème avec le parser SAX


Sujet :

Bibliothèques et frameworks PHP

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 4
    Points : 2
    Points
    2
    Par défaut [XML] 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 : 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
    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

  2. #2
    Nouveau Candidat au Club
    Inscrit en
    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

Discussions similaires

  1. problème avec le parseur SAX
    Par xblond dans le forum Format d'échange (XML, JSON...)
    Réponses: 4
    Dernier message: 06/06/2006, 10h22
  2. [FLASH 8] [XML] Problème avec XML.load() asynchrone
    Par SSJ17Vegeta dans le forum Flash
    Réponses: 1
    Dernier message: 20/01/2006, 18h47
  3. [XML] Problème avec &
    Par s3r3nity dans le forum Valider
    Réponses: 5
    Dernier message: 21/12/2005, 14h13
  4. Problème avec le parser XML
    Par sheura dans le forum XML/XSL et SOAP
    Réponses: 3
    Dernier message: 09/11/2005, 18h26
  5. Valider fichier XML : problème avec la DTD
    Par SkIllz2k dans le forum Valider
    Réponses: 2
    Dernier message: 26/04/2005, 17h15

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo