Prev: CFileDialog Does not show mapped files in system account
Next: multithreaded dll - what is going on in std::_Lockit?
From: Håvard Olerud Eriksen on 16 Mar 2007 10:22 I'm trying to add a processing instruction to an xml document. I've found a few instructions on the web but when I try to do the same I get an error message saying: Error 1 error C2664: 'MSXML2::IXMLDOMNode::insertBefore' : cannot convert parameter 1 from 'IXMLDOMProcessingInstructionPtr' to 'MSXML2::IXMLDOMNode *' The code looks like this: bool Init() { pXMLDoc_ = NULL; HRESULT hr; hr = pXMLDoc_.CreateInstance("Msxml2.DOMDocument.6.0"); if (FAILED(hr)) { std::cerr << "Error, can't create DOM" << std::endl; return false; } pXMLDoc_->async = false; IXMLDOMProcessingInstructionPtr pPI = NULL; pPI = pXMLDoc_->createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'"); _variant_t nullVal; nullVal.vt = VT_NULL; pXMLDoc_->insertBefore(pPI, nullVal); return true; } What am I missing here? Any help is much appreciated! Håvard
From: David Lowndes on 16 Mar 2007 10:48 >I'm trying to add a processing instruction to an xml document. I've >found a few instructions on the web but when I try to do the same I >get an error message saying: >Error 1 error C2664: 'MSXML2::IXMLDOMNode::insertBefore' : cannot >convert parameter 1 from 'IXMLDOMProcessingInstructionPtr' to >'MSXML2::IXMLDOMNode *' >The code looks like this: > IXMLDOMProcessingInstructionPtr pPI = NULL; > pPI = pXMLDoc_->createProcessingInstruction("xml", "version='1.0' >encoding='UTF-8'"); > _variant_t nullVal; > nullVal.vt = VT_NULL; > pXMLDoc_->insertBefore(pPI, nullVal); H�vard, You probably don't want to use insertBefore there since you've only just got your document. Here's what works for me: IXMLDOMProcessingInstructionPtr pi = pDoc->createProcessingInstruction( "xml", "version='1.0' encoding='UTF-8'" ); pDoc->appendChild( pi ); Dave
From: Alex Blekhman on 16 Mar 2007 11:09 Here's working example that doesn't have any casting problems: -------------------------------------------------- #import <msxml6.dll> int _tmain(int /*argc*/, _TCHAR* /*argv*/[]) { ::CoInitialize(NULL); MSXML2::IXMLDOMDocument2Ptr ptrXmlDoc( __uuidof(MSXML2::DOMDocument60)); ptrXmlDoc->async = VARIANT_FALSE; ptrXmlDoc->loadXML(L"<hello/>"); MSXML2::IXMLDOMProcessingInstructionPtr ptrPI = ptrXmlDoc->createProcessingInstruction(L"xml", L"version='1.0' encoding='UTF-8'"); ptrXmlDoc->insertBefore(ptrPI, ptrXmlDoc->documentElement.GetInterfacePtr()); ptrPI = NULL; ptrXmlDoc->save(L"Test.xml"); ptrXmlDoc = NULL; ::CoUninitialize(); return 0; } -------------------------------------------------- Alex
From: Håvard Olerud Eriksen on 19 Mar 2007 04:20
On Mar 16, 4:09 pm, "Alex Blekhman" <x...(a)oohay.moc> wrote: > Here's working example that doesn't have any casting > problems: > > -------------------------------------------------- > #import <msxml6.dll> > > int _tmain(int /*argc*/, _TCHAR* /*argv*/[]) > { > ::CoInitialize(NULL); > > MSXML2::IXMLDOMDocument2Ptr ptrXmlDoc( > __uuidof(MSXML2::DOMDocument60)); > ptrXmlDoc->async = VARIANT_FALSE; > ptrXmlDoc->loadXML(L"<hello/>"); > > MSXML2::IXMLDOMProcessingInstructionPtr ptrPI = > ptrXmlDoc->createProcessingInstruction(L"xml", > L"version='1.0' encoding='UTF-8'"); > > ptrXmlDoc->insertBefore(ptrPI, > ptrXmlDoc->documentElement.GetInterfacePtr()); > ptrPI = NULL; > > ptrXmlDoc->save(L"Test.xml"); > ptrXmlDoc = NULL; > > ::CoUninitialize(); > > return 0;} > > -------------------------------------------------- > > Alex Thanks guy for the prompt reply. I went with the last version and it worked like a charm! Håvard |