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

MFC Discussion :

[Xerces] probleme avec SAX


Sujet :

MFC

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    116
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 116
    Points : 40
    Points
    40
    Par défaut [Xerces] probleme avec SAX
    Bonjour,
    j'ai réaliser une appli qui utilise SAX pour lire un fichier Xml grace à la librairie Xerces.
    Dans cette appli, ma class CSAXHandlers, qui permet de lire le fixhier Xml, dirigait l'application.
    C'est à dire, dans la fonction :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    void CSAXHandlers::characters(const     XMLCh* const    chars                                   , const   unsigned int    length)
    j'exécutais des événement selon le noeud.

    Je voudrais que la class CSAXHandlers, ne dirige plus l'appli. Mais qu'une autre class, class Interface, face appelle à la class CSAXHandlers pour obtenir les valeurs désiraient.

    Malheureusement, quand à partir de la class Interface, je fais appelle à la class CSAXHandlers j'obtiens un plantage avec la belle pop-up me disant de l'appli a rentontré un problème et doit fermer :-(

    Cela est du au fait qu'a chaque appelle d'une valeur, j'obtiens une valeur null.

    Comment résoudre mon problème?

    merci

    (PS: Si ce n'est pas clair, ne pas hésiter à me le dire)

  2. #2
    Membre du Club Avatar de jlassira
    Inscrit en
    Mai 2005
    Messages
    228
    Détails du profil
    Informations forums :
    Inscription : Mai 2005
    Messages : 228
    Points : 61
    Points
    61
    Par défaut
    Es tu sur que le parsing de ton fichier xml se fait convenablement? as tu essayé de debugueer ton application et voir si les valeurs des noeuds sont bien extraites!

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    116
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 116
    Points : 40
    Points
    40
    Par défaut
    le parsing se fait bien.
    en effet, les variable présent dans la class qui parse sont bien renseignées avec les bonnes valeur.
    mais je n'arrive pas à faire appele à ces variale depuis une autre class. Pour copier le contenu de la valeur par exemple.

    voici une partie de mon code :

    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
    int CSAXHandlers::ParseFile(char * file)
    {
    	static bool                     doNamespaces        = false;
    	static bool                     doSchema            = false;
    	static bool                     schemaFullChecking  = false;
    	static const char  *            encodingName		= "LATIN1";
    	static SAXParser::ValSchemes    valScheme			= SAXParser::Val_Auto;
     
    	// Initialize the XML4C2 system
        try
        {
             XMLPlatformUtils::Initialize();
        }
     
        catch (const XMLException&)
        {
             XERCES_STD_QUALIFIER cerr << "Error during initialization! :\n" << endl;
             return 1;
        }
     
        int errorCount = 0;
     
        //
        //  Create a SAX parser object. Then, according to what we were told on
        //  the command line, set it to validate or not.
        //
        SAXParser* parser = new SAXParser;
        parser->setValidationScheme(valScheme);
        parser->setDoNamespaces(doNamespaces);
        parser->setDoSchema(doSchema);
        parser->setValidationSchemaFullChecking(schemaFullChecking);
     
        //
        //  Create the handler object and install it as the document and error
        //  handler for the parser-> Then parse the file and catch any exceptions
        //  that propogate out
        //
        int errorCode = 0;
        try
        {
            CSAXHandlers handler;
            parser->setDocumentHandler(&handler);
            parser->setErrorHandler(&handler);
            parser->parse(file);
            errorCount = parser->getErrorCount();
        }
        catch (const OutOfMemoryException&)
        {
            XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
            errorCode = 5;
        }
        catch (const XMLException&)
        {
            XERCES_STD_QUALIFIER cerr << "\nAn error occurred\n  Error: " <<  endl;
            errorCode = 4;
        }
        if(errorCode) {
            XMLPlatformUtils::Terminate();
            return errorCode;
        }
     
        //
        //  Delete the parser itself.  Must be done prior to calling Terminate, below.
        //
        delete parser;
     
        // And call the termination method
        XMLPlatformUtils::Terminate();
     
    	if (errorCount > 0)
            return 4;
        else
            return 0;
    }

    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
    void CSAXHandlers::startElement(const   XMLCh* const    name
                                        ,       AttributeList&  attributes)
    {
        g_nomDuNoeud=XMLString::transcode(name);
     
    	unsigned int len = attributes.getLength();
        for (unsigned int index = 0; index < len; index++)
        {
            //
            //  Again the name has to be completely representable. But the
            //  attribute can have refs and requires the attribute style
            //  escaping.
            //
            g_nomDeAttribut = XMLString::transcode(attributes.getName(index));
     
     
    		if (!strcmp(g_nomDeAttribut,"linkFED")){
    			g_FED = XMLString::transcode(attributes.getValue(index));
    			cout << " -- g_FED --  " << g_FED << endl;
    		}
    		else if (!strcmp(g_nomDeAttribut,"linkRTI")){
    			g_RTI = XMLString::transcode(attributes.getValue(index));
    		}
    		else if (!strcmp(g_nomDeAttribut,"linkSce")){
    			g_SCENARIO = XMLString::transcode(attributes.getValue(index));
    			cout << "g_SCENARIO  : " << g_SCENARIO << endl;
    		}
     
        }
    }
    j'ai un probleme pour appeler cette class :
    là je fais comme ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    CSAXHandlers  SaxDlg;
    SaxDlg.ParseFile("config.xml");
    j'avais pensé faire l'appelle comme ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    void Interface::initSimulation()
    {
       SaxDlg = new CSAXHandlers();
       SaxDlg->ParseFile("config.xml");
    }
    mais j'ai ce message d'erreur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    C:\ConsoleHLA\modules\Interface\Src\Interface.cpp(29) : error C2247: 'new' not accessible because 'xercesc_2_6::XMLFormatTarget' uses 'public' to inherit from 'xercesc_2_6::XMemory'
            c:\xerces\xerces-c_2_6_0-windows_nt-msvc_60\include\xercesc\util\xmemory.hpp(54) : see declaration of 'new'
    C:\ConsoleHLA\modules\Interface\Src\Interface.cpp(29) : error C2247: 'delete' not accessible because 'xercesc_2_6::XMLFormatTarget' uses 'public' to inherit from 'xercesc_2_6::XMemory'
            c:\xerces\xerces-c_2_6_0-windows_nt-msvc_60\include\xercesc\util\xmemory.hpp(88) : see declaration of 'delete'
    Error executing cl.exe.

  4. #4
    Membre du Club Avatar de jlassira
    Inscrit en
    Mai 2005
    Messages
    228
    Détails du profil
    Informations forums :
    Inscription : Mai 2005
    Messages : 228
    Points : 61
    Points
    61
    Par défaut
    tu n'arrive pas a les acceder comment? sont elles declarées private ou autre au lieu d'etre publics dans la classe ou elles sont définies? as tu bien inclus cetet classe dans le .cpp de ta classe appelante?

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    116
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 116
    Points : 40
    Points
    40
    Par défaut
    ma classe est déclaré de cette manière :

    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
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    #if !defined(AFX_SAXHANDLERS_H__0BAD5B01_5387_41F8_9359_3C65B3C67E41__INCLUDED_)
    #define AFX_SAXHANDLERS_H__0BAD5B01_5387_41F8_9359_3C65B3C67E41__INCLUDED_
     
    #include    <xercesc/sax/HandlerBase.hpp>
    #include    <xercesc/framework/XMLFormatter.hpp>
    #include	"TollsKit_HLA\Header\Federate.h"
    #include	"DOMWrite.h"
     
     
    XERCES_CPP_NAMESPACE_USE
     
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
     
     
     
    class CSAXHandlers : public HandlerBase, private XMLFormatTarget
    {
    public:
    	CSAXHandlers();
    	virtual ~CSAXHandlers();
     
    	int ParseFile(char * file);
     
    	// -----------------------------------------------------------------------
        //  Implementations of the format target interface
        // -----------------------------------------------------------------------
        void writeChars
        (
            const   XMLByte* const  toWrite
        );
     
        void writeChars
        (
            const   XMLByte* const  toWrite
            , const unsigned int    count
            , XMLFormatter* const   formatter
        );
     
     
        // -----------------------------------------------------------------------
        //  Implementations of the SAX DocumentHandler interface
        // -----------------------------------------------------------------------
        void endDocument();
     
        void endElement(const XMLCh* const name);
     
        void characters(const XMLCh* const chars, const unsigned int length);
     
        void ignorableWhitespace
        (
            const   XMLCh* const    chars
            , const unsigned int    length
        );
     
        void processingInstruction
        (
            const   XMLCh* const    target
            , const XMLCh* const    data
        );
     
        void startDocument();
     
        void startElement(const XMLCh* const name, AttributeList& attributes);
     
     
     
        // -----------------------------------------------------------------------
        //  Implementations of the SAX ErrorHandler interface
        // -----------------------------------------------------------------------
        void warning(const SAXParseException& exc);
        void error(const SAXParseException& exc);
        void fatalError(const SAXParseException& exc);
     
     
     
        // -----------------------------------------------------------------------
        //  Implementation of the SAX DTDHandler interface
        // -----------------------------------------------------------------------
        void notationDecl
        (
            const   XMLCh* const    name
            , const XMLCh* const    publicId
            , const XMLCh* const    systemId
        );
     
        void unparsedEntityDecl
        (
            const   XMLCh* const    name
            , const XMLCh* const    publicId
            , const XMLCh* const    systemId
            , const XMLCh* const    notationName
        );
     
    	char * setScenario();
     
     
    	CFederate	*	_myFederate;
    	CDOMWrite	*	_myDOMWrite;
     
     
     
    	char *			g_FED;
    	char *			g_SCENARIO;
    	char *			g_RTI;
    	char *			g_nomDuNoeud;
    	char *			g_nomDeAttribut;
    	char *			g_valeurDeAttribut;
    	char *			g_nameSimulation;
    	char *			g_typeSimulation;
    	char *			g_federate;
    	char *			g_federation;
    	int				g_lrcTn;		
    	int				g_localTn;		
    	int				g_deltaT;		
    	char *			g_nat;		
    	char *			g_scr;		
    	int				g_azimuth;
    	int				g_range;
    	char *			g_latitude;
     
    	char *			g_longitude;
    	int				g_course;
    	int				g_speed;
    	char *			g_name;
    	char *			g_environment;
    	char *			g_trackIndentity;
    	char *			g_trackPriId;
    	char *			g_trackSecId;
     
     
     
    };
     
    #endif // !defined(AFX_SAXHANDLERS_H__0BAD5B01_5387_41F8_9359_3C65B3C67E41__INCLUDED_)
    et j'ai bien inclu le .h

  6. #6
    Membre du Club Avatar de jlassira
    Inscrit en
    Mai 2005
    Messages
    228
    Détails du profil
    Informations forums :
    Inscription : Mai 2005
    Messages : 228
    Points : 61
    Points
    61
    Par défaut
    montre nous comment tu les appelles dans la deuxieme classe c'est adire DOMWrite.cpp si je ne trompe pas .

  7. #7
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    116
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 116
    Points : 40
    Points
    40
    Par défaut
    je les appelle dans la class Interface de cette manière :

    .h

    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
    class Interface
    {
    public:
    	Interface();
    	virtual ~Interface();
     
    	void initSimulation();
     
    	CSAXHandlers    SaxDlg;
     
    	char *			g_FED;
    	char *			g_SCENARIO;
    	char *			g_RTI;
    	char *			g_nomDuNoeud;
    	char *			g_nomDeAttribut;
    	char *			g_valeurDeAttribut;
    	char *			g_nameSimulation;
    	char *			g_typeSimulation;
    	char *			g_federate;
    	char *			g_federation;
    	int				g_lrcTn;		
    	int				g_localTn;		
    	int				g_deltaT;		
    	char *			g_nat;		
    	char *			g_scr;		
    	int				g_azimuth;
    	int				g_range;
    	char *			g_latitude;
    	char *			g_longitude;
    	int				g_course;
    	int				g_speed;
    	char *			g_name;
    	char *			g_environment;
    	char *			g_trackIndentity;
    	char *			g_trackPriId;
    	char *			g_trackSecId;
     
    };

    .cpp

    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
    Interface::Interface()
    {
    	initSimulation();
    }
     
    Interface::~Interface()
    {
     
    }
     
     
    void Interface::initSimulation()
    {
    	CSAXHandlers SaxDlg;
    	SaxDlg.ParseFile("config.xml");
            g_nomDuNoeud = SaxDlg.g_FED;[color=red] //tjrs null[/color]
    }

  8. #8
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    116
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 116
    Points : 40
    Points
    40
    Par défaut
    Quequ'un aurait-il une idée?

  9. #9
    Membre du Club Avatar de jlassira
    Inscrit en
    Mai 2005
    Messages
    228
    Détails du profil
    Informations forums :
    Inscription : Mai 2005
    Messages : 228
    Points : 61
    Points
    61
    Par défaut
    declare les en tant que public c'est ca ton erreur apparramment!

  10. #10
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    116
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 116
    Points : 40
    Points
    40
    Par défaut
    elles sont déjà déclaré public !!!

Discussions similaires

  1. [SAX] org.xml.sax.SAXParseException probleme avec &nbsp
    Par rasenganguy dans le forum Format d'échange (XML, JSON...)
    Réponses: 14
    Dernier message: 10/05/2012, 09h54
  2. [SAX] probleme du parsing avec SAX
    Par fibi007 dans le forum Format d'échange (XML, JSON...)
    Réponses: 7
    Dernier message: 09/06/2008, 12h59
  3. Probleme avec Xerces
    Par jalelouss dans le forum XML
    Réponses: 0
    Dernier message: 30/08/2007, 17h08
  4. [SAX] Probleme avec SAX
    Par <% Bastien %> dans le forum Format d'échange (XML, JSON...)
    Réponses: 5
    Dernier message: 28/02/2007, 16h08
  5. [DOM] probleme avec les exemples Xerces.
    Par brune dans le forum Format d'échange (XML, JSON...)
    Réponses: 2
    Dernier message: 26/05/2004, 10h23

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