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

Vue hybride

Message pr�c�dent Message pr�c�dent   Message suivant Message suivant
  1. #1
    Membre confirm�
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    116
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 116
    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 confirm� Avatar de jlassira
    Inscrit en
    Mai 2005
    Messages
    228
    D�tails du profil
    Informations forums :
    Inscription : Mai 2005
    Messages : 228
    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 confirm�
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    116
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 116
    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 confirm� Avatar de jlassira
    Inscrit en
    Mai 2005
    Messages
    228
    D�tails du profil
    Informations forums :
    Inscription : Mai 2005
    Messages : 228
    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 confirm�
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    116
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 116
    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 confirm� Avatar de jlassira
    Inscrit en
    Mai 2005
    Messages
    228
    D�tails du profil
    Informations forums :
    Inscription : Mai 2005
    Messages : 228
    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 confirm�
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    116
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 116
    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 confirm�
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    116
    D�tails du profil
    Informations personnelles :
    Localisation : France

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

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

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

    Informations forums :
    Inscription : Avril 2003
    Messages : 116
    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