Introduction
This is the Pocket PC version of Frank Le's, "How to load a tree view with a large XML file". I got permission from Frank to post the CE or Pocket PC version of his program. It's been a couple of months after I implemented the Pocket PC version and never had time, until now, to document and upload it. It's now over a year later, so here goes.
Initializing COM:
hr = CoInitializeEx(NULL,COINIT_MULTITHREADED);
Next, the following bit of code must be executed. But I don't remember why. It's something about document safety options. If someone does know, please post the reason.
IObjectSafety* pSafety;
DWORD dwSupported, dwEnabled;
if ( SUCCEEDED(document->QueryInterface( IID_IObjectSafety,
(void**)&pSafety ) ) )
{
pSafety->GetInterfaceSafetyOptions(MSXML::IID_IXMLDOMDocument,
&dwSupported, &dwEnabled );
pSafety->SetInterfaceSafetyOptions(MSXML::IID_IXMLDOMDocument,
dwSupported, 0 );
}
The following code uses the FileStream
to load an XML file into the DOM. You need to get the FileStream.h file for this (included in the zip file).
VARIANT vXMLSrc;
VARIANT_BOOL vSuccess;
VariantInit( &vXMLSrc );
FileStream* fs = new FileStream;
fs->open(strPathName);
vXMLSrc.punkVal = fs;
vXMLSrc.vt = VT_UNKNOWN;
hr = document->load(vXMLSrc, &varOkay);
if (FAILED(hr))
return FALSE;
Lastly,
node->hasChildNodes()
is replaced with:
VARIANT_BOOL vbHasChild;
node->hasChildNodes(&vbHasChild);
if (vbHasChild) {
I have forgotten why, and it may not be necessary. The code does work though. I have included an ARM exe with the zip file.
I used the DOM in some of my programs here and it worked pretty well.