XML methode cloneNode(VARIANT_BOOL deep) interface IXMLDOMNode

Signaler
Messages postés
39
Date d'inscription
jeudi 27 février 2003
Statut
Membre
Dernière intervention
31 janvier 2006
-
Messages postés
39
Date d'inscription
jeudi 27 février 2003
Statut
Membre
Dernière intervention
31 janvier 2006
-
Salut,

j'ai qq soucis avec la méthodes clonNode de l'interface IXMLDOMNode, une erreur d'accès mémoire donc voici le code :

//Header XMLDoc.h-----------------------------------------------

#pragma once
#ifndef XMLDOC_H
#define XMLDOC_H
#include "HeaderFile.h"
#import "msxml4.dll" named_guids
using namespace MSXML2;

class XMLDoc
{
public:
MSXML2::IXMLDOMDocument2Ptr m_pXmlDoc;
MSXML2::IXMLDOMElementPtr m_pRootNode;
string m_strXML;
MSXML2::IXMLDOMNode* m_pNodeCurrent;
public:
XMLDoc(void);
XMLDoc(string pathfile);
~XMLDoc(void);
public:
HRESULT LoadFile(string path);
HRESULT LoadXML(string xml);
};

class XMLNode
{
public:
XMLNode(void);
XMLNode(MSXML2::IXMLDOMNode *node);
~XMLNode(void);
protected://Membres privés
MSXML2::IXMLDOMNode* m_pNode;
public://Operateurs
void operator<<(MSXML2::IXMLDOMNode* node);
XMLNode operator=(MSXML2::IXMLDOMNode* node);
bool operator!=(void* test)
{
return (m_pNode != test);
}
public://Membres publics
MSXML2::IXMLDOMDocument* m_pOwnerDocument;
MSXML2::IXMLDOMNode* m_pPreviousNode;
MSXML2::IXMLDOMNode* m_pParentNode;
MSXML2::IXMLDOMNode* m_pNextNode;
string m_strNodeName;
string m_strNodeText;
public://Methodes publics
MSXML2::IXMLDOMNode* ChildAt(long Index);
};
#endif
//-------------------------------------------------------------------

//Fichier XMLDoc.cpp----------------------------------------------

#include "xmldoc.h"
/********************************************************************************************************
Class XMLDoc
********************************************************************************************************/
XMLDoc::XMLDoc(void)
{
CoInitialize(NULL);
HRESULT hr = m_pXmlDoc.CreateInstance(CLSID_DOMDocument40);
if(FAILED(hr))
{
m_pXmlDoc = NULL;
m_pRootNode = NULL;
}
}

XMLDoc::XMLDoc(string pathfile)
{
CoInitialize(NULL);
HRESULT hr = m_pXmlDoc.CreateInstance(CLSID_DOMDocument40);
if(FAILED(hr))
{
m_pXmlDoc = NULL;
m_pRootNode = NULL;
}
if(m_pXmlDoc != NULL)
{
m_pXmlDoc->load(pathfile.c_str());
m_strXML = m_pXmlDoc->xml;
m_pRootNode = m_pXmlDoc->GetdocumentElement();
m_pNodeCurrent = m_pXmlDoc->firstChild->cloneNode(true);
}
}

HRESULT XMLDoc::LoadFile(string path)
{
if(m_pXmlDoc != NULL)
{
m_pXmlDoc->load(path.c_str());
m_strXML = m_pXmlDoc->xml;
m_pRootNode = m_pXmlDoc->GetdocumentElement();
m_pNodeCurrent = m_pXmlDoc->firstChild;
}
return S_OK;
}

XMLDoc::~XMLDoc(void)
{
if(m_pNodeCurrent != NULL)
m_pNodeCurrent->Release();
if(m_pRootNode != NULL)
m_pRootNode->Release();
if(m_pXmlDoc != NULL)
m_pXmlDoc->Release();
}
/********************************************************************************************************
Fin Class XMLDoc
********************************************************************************************************/

/********************************************************************************************************
Class XMLNode
********************************************************************************************************/
XMLNode::XMLNode(void)
{
m_pNode = NULL;
m_pOwnerDocument = NULL;
m_pParentNode = NULL;
m_pPreviousNode = NULL;
m_pNextNode = NULL;
}

XMLNode::XMLNode(MSXML2::IXMLDOMNode *node)
{
m_pNode = node->cloneNode(true); <== L'erreur se manifeste ici
m_strNodeName = m_pNode->GetnodeName();
m_pOwnerDocument = m_pNode->GetownerDocument();
m_pParentNode = m_pNode->GetparentNode();
m_pPreviousNode = m_pNode->GetpreviousSibling();
m_pNextNode = m_pNode->GetnextSibling();
}

XMLNode::~XMLNode(void)
{
}

void XMLNode::operator<<(MSXML2::IXMLDOMNode* node)
{
m_pNode = node->cloneNode(TRUE);
m_strNodeName = m_pNode->GetnodeName();
m_pOwnerDocument = m_pNode->GetownerDocument();
m_pParentNode = m_pNode->GetparentNode();
m_pPreviousNode = m_pNode->GetpreviousSibling();
m_pNextNode = m_pNode->GetnextSibling();
}

XMLNode XMLNode::operator =(MSXML2::IXMLDOMNode* node)
{
XMLNode result(node);
return result;
}

MSXML2::IXMLDOMNode* XMLNode::ChildAt(long Index)
{
MSXML2::IXMLDOMNodeList* pNodeList;
m_pNode->get_childNodes(&pNodeList);
return (MSXML2::IXMLDOMNode*)pNodeList->Getitem(Index);
}
/********************************************************************************************************
Fin Class XMLNode
********************************************************************************************************/

//-------------------------------------------------------------------

si qqn peut m'aider à résoudre ce problème ou me dire pkoi celà n'est pas possible je comprends pas bien l'erreur.
Merci d'avance :)

1 réponse

Messages postés
39
Date d'inscription
jeudi 27 février 2003
Statut
Membre
Dernière intervention
31 janvier 2006

oups j'ai oublié le main et les Headers :

//Header HeaderFile.h
#include <stdio.h>
#include <string>
#include
#include <windows.h>

using namespace std;

//Fichier Main.cpp
#include "HeaderFile.h"
#include "XmlDoc.h"

int main(int argc, char* argv[])
{
XMLDoc MyDoc("c:\\test.xml");
XMLNode Node(MyDoc.m_pNodeCurrent);

if(Node != NULL)
{
string test = Node.ChildAt(0)->xml;
cout << test << endl;
}
getchar();
CoUninitialize();
return 0;
}