[xml] What's the problem?



Here is a sample of my program which doesn’t work.

 

I try to retrieve the rood node through an xml tree.

 

 

 

#include <iostream.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <errno.h>

#include <sys/types.h>

#include <sys/stat.h>

 

 

#ifdef CPLUSPLUS

 

extern "C"

{

#endif

            #include <libxml/parser.h>

            #include <libxml/tree.h>

            #include <libxml/xpath.h>

            #include <libxml/xmlmemory.h>

#include <libxslt/xslt.h>

 

#ifdef CPLUSPLUS

}

#endif

 

 

 

int main(int argc, char **argv) {

 

           

/**** affectation des chaines de caractere utilisées dans le fichier xml  ***/

/*

            const char * morceau = "morceau";

            const char * song = "song";

            const char * first = "first";

            */

           

/**** Déclarations des pointeurs  ***/

           

            xmlDocPtr xmldoc = NULL;

            xmlXPathContextPtr xmldoc_context = NULL;

            xmlXPathObjectPtr xmlobject;

            xmlNodePtr root;

 

           

/**** Vérification de la création de xmldoc et de la valeur 0 pour ce meme ***/

            if (!xmldoc)

            {

                        cout <<"là c'est bon\n";

            }

 

/**** Arborescence xpath on veu récupérer le text sous song ***/

            const char path_template[] ="morceau/first/song/text()";

            xmlChar *path;

            xmldoc = xmlParseFile("structsimple.xml");

            if (!xmldoc)

            {

                        cout <<"damn"; //si le parsing est pas bon

 

            }

            if (xmldoc)

            {

                        cout <<"doc parse\n";

            }

 

            root = xmlDocGetRootElement(xmldoc);

        printf("Document root element name is %s\n", root->name);

 

 

return 1;

 

}

 

structsimple.xml

 

<?xml version="1.0"?>

<morceau><first><song n="001"/>

            </first></morceau>

 

The matter is that after the parsing which seems to work, the xmlGetRootElement such as others xml commands like xmlXPathInit (that’s my problem!)… doesn’t work and make my program crash.

 

I work on win xp and visual C++.

 

Can you help me with this one?

 

De - Fre



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]