MSXML: troubles with "insertBefore" in Microsoft Visual C++
-
Hi Gurus! I have the simplest xml document (d:\\book.xml): <?xml version="1.0"?> <Report> ... </Report> I've written the small program (inserting XSL reference in the prolog): Dim xmlDoc,pi,ref set xmlDoc = CreateObject ("Msxml.DOMDocument") xmlDoc.async = false xmlDoc.resolveExternals = false xmlDoc.load ("d:\\book.xml") ref="type=""text/xsl"" href=""mysheet.xsl""" set pi = xmlDoc.createProcessingInstruction("xml-stylesheet",ref) xmlDoc.insertBefore pi,xmlDoc.childNodes.item(1) WScript.Echo(xmlDoc.xml) It works fine! Next, I tried to do the same using Microsoft Visual C++: IXMLDOMDocumentPtr XmlDocPtr; _bstr_t bstrXMLReport(_T("d:\\book.xml"); VARIANT_BOOL vtResult; HRESULT hr = XmlDocPtr.CreateInstance(MSXML::CLSID_DOMDocument); if (FAILED(hr)) { AfxMessageBox("Failed to CreateInstance(CLSID_DOMDocument)"); return; }; XmlDocPtr->async=FALSE; XmlDocPtr->resolveExternals=FALSE; vtResult=XmlDocPtr->load(bstrXMLReport); if (vtResult == VARIANT_FALSE) { AfxMessageBox("Failed to load XML document"); return; }; IXMLDOMProcessingInstructionPtr pi; _bstr_t bstrTarget(_T("xml-stylesheet")); _bstr_t bstrData(_T("type=\"text/xsl\" href=\"mysheet.xsl\"")); pi=XmlDocPtr->createProcessingInstruction(bstrTarget,bstrData); BSTR qqq; pi->get_xml(&qqq); CComVariant varRef; IXMLDOMNodePtr pFirst,pXMLNodeCur; XmlDocPtr->childNodes->get_item(1,&pFirst); varRef=pFirst; try { XmlDocPtr->insertBefore(pi,t); AfxMessageBox(XmlDocPtr->xml); } catch(_com_error &er) { TCHAR szErr[MAX_PATH]; memset(szErr,0,sizeof(szErr)); _tcscpy(szErr,(LPCTSTR)er.Description()); AfxMessageBox(szErr); }; After that, I've got the exception "The parameter is incorrect." Why? I suspect the incorrect usage of insertBefore method. What should I do? Yours sincerely, Alex Bash