Loading an XML File From Disk
The snippet below details the usual steps performed to load an XML file from disk into Microsoft's parser. The document pointer (m_pXMLDoc) would have been obtained when an instance of the parser was created via a CoCreateInstance call.
// Don't load the document asynchronously
VARIANT_BOOL vStatus = VARIANT_FALSE;
VARIANT_BOOL vAsync = VARIANT_FALSE;
m_pXMLDoc->put_async(vAsync);
// Use XPath syntax for document queries
CComVariant vSyntax("XPath");
BSTR bstrLanguage = ::SysAllocString(_T("SelectionLanguage"));
m_pXMLDoc->setProperty(bstrLanguage, vSyntax);
// Load the specified XML document
CComVariant vXMLFile(strXMLFilename.c_str());
if((m_pXMLDoc->load(vXMLFile, &vStatus) == S_OK) &&
(vStatus == VARIANT_TRUE))
{
hResult = S_OK;
}
FREE_BSTR(bstrLanguage);
strXMLFilename.c_str() represents the full path and name of the target XML file. The last line, FREE_BSTR, is just a macro which releases memory associated with selection language BSTR.
#define FREE_BSTR(bstr){if(bstr){::SysFreeString(bstr); bstr = 0;}}