How to load xml file from resources using msxml?
-
IXLMDOMDocument2Ptr pDoc; // test.xml (UTF-8) encoded, : //你好, hello // check in IE, no problem. // resource type HTML, or BINARY tried. // ... create pDoc, find resource, loadresouce, // create IStream on HGlobal, everything seems ok // and i checked the dubug info, show xml content correctly, // and setting the IStream to the beginning of IStream // but... pDoc->async = VARIANT_FALSE; pDoc->load(_variant_t(pStream)); // FAILs, it complains that no top level element in xml. // but, when i write the stream into a disk file, // and load form file, it's OK !!! // if use loadXML((LPTSTR)hGlobal) the charactor shown is not correct.
-
IXLMDOMDocument2Ptr pDoc; // test.xml (UTF-8) encoded, : //你好, hello // check in IE, no problem. // resource type HTML, or BINARY tried. // ... create pDoc, find resource, loadresouce, // create IStream on HGlobal, everything seems ok // and i checked the dubug info, show xml content correctly, // and setting the IStream to the beginning of IStream // but... pDoc->async = VARIANT_FALSE; pDoc->load(_variant_t(pStream)); // FAILs, it complains that no top level element in xml. // but, when i write the stream into a disk file, // and load form file, it's OK !!! // if use loadXML((LPTSTR)hGlobal) the charactor shown is not correct.
It should not be much of a problem. I do it like this in a project (With all error handling removed. It just clutters up the example.)
int CHookApp::LoadXML (int rsrc, MSXML2::IXMLDOMDocument2Ptr& xml, CString& errMsg) { HRSRC hXSLResourceInfoBlock; HGLOBAL hXSLResource; hXSLResourceInfoBlock = ::FindResource (m_hInstance, MAKEINTRESOURCE(rsrc), "XSL"); if (hXSLResourceInfoBlock) hXSLResource = LoadResource (m_hInstance, hXSLResourceInfoBlock); if (hXSLResourceInfoBlock == NULL || hXSLResource == NULL) return -1; try { _bstr_t xmlText ((char*)LockResource (hXSLResource)); if (xml->loadXML ( xmlText ) == VARIANT_FALSE) return -1; } catch (...) { return -1; } return 0; }
I wonder why my empty lines are removed from the <pre> block above. It remained in another reply of mine....... -- modified at 5:03 Wednesday 14th December, 2005