Introduction
This wrapper class - wraps around functions for XML access, storage and retrieval of data. It allows easy access and manipulation of data stored as an XML file. The usage is very easy and is perfect for any serialization needs especially of a tree based data.
Usage
First include the XMLManager.h and XMLManager.cpp files in your project.
Create an instance of the class:
CXMLManager xmlManager;
Don't forget to include the XML support in your project:
#import "msxml.dll" named_guids raw_interfaces_only
Usually in your stdafx.h.
Create an XML document pointer:
HRESULT hr = S_OK;
MSXML::IXMLDOMDocument *pDoc = NULL;
CoInitialize(NULL);
CHECKHR(CoCreateInstance(MSXML::CLSID_DOMDocument, NULL,
CLSCTX_INPROC_SERVER,
MSXML::IID_IXMLDOMDocument,
(void**)&pDoc));
Now use the XMLManager in the folowing way:
Serialization:
HRESULT CXMLManager::LoadDocument(
MSXML::IXMLDOMDocument *pDoc,
char* fileName
);
HRESULT CXMLManager::SaveDocument(
MSXML::IXMLDOMDocument *pDoc,
char* fileName
);
Data retrieval:
MSXML::IXMLDOMNode* CXMLManager::GetChild(
MSXML::IXMLDOMNode *pNode,
CString name
);
CString CXMLManager::GetNodeName(
MSXML::IXMLDOMNode *pNode
);
long CXMLManager::GetIntegerAttribute(
MSXML::IXMLDOMNode* pNode,
CString attName
);
double CXMLManager::GetDoubleAttribute(
MSXML::IXMLDOMNode* pNode,
CString attName
);
CString CXMLManager::GetStringAttribute(
MSXML::IXMLDOMNode* pNode,
CString attName
);
Data storage:
MSXML::IXMLDOMNode * CXMLManager::CreateDOMNode(
MSXML::IXMLDOMDocument* pDoc,
int type,
CString nodeName
);
CXMLManager::SetIntegerAttribute(
MSXML::IXMLDOMNode* pNode,
CString attName,
long val
);
CXMLManager::SetDoubleAttribute(
SXML::IXMLDOMNode* pNode,
String attName,
double val
);
CXMLManager::SetStringAttribute(
MSXML::IXMLDOMNode* pNode,
CString attName,
CString val
);
Example of usage
MSXML::IXMLDOMDocument *pDoc = NULL;
CoInitialize(NULL);
CHECKHR(CoCreateInstance(MSXML::CLSID_DOMDocument,
NULL, CLSCTX_INPROC_SERVER,
MSXML::IID_IXMLDOMDocument, (void**)&pDoc));
CHECKHR(xmlManager.LoadDocument(pDoc,"C:\\Test.xml"));
MSXML::IXMLDOMNode *pNode = pNode = xmlManager.CreateDOMNode(
pDoc,MSXML::NODE_ELEMENT, "New Node");
xmlManager.SetStringAttribute(pNode,"String","Sample data");
xmlManager.SetStringAttribute(pNode,"Integer",56872);
xmlManager.SetStringAttribute(pNode,"Double",35.264);
pDoc->appendChild(pNode, NULL);
xmlManager.SaveDocument(pDoc,,"C:\\Test.xml"));
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.