-
July 13th, 2003, 12:39 PM
#1
XML DOM Document 3.0
I want to make work with XML files in a MFC App.
IXMLDOMDocument *pXML;
HRESULT hr;
hr = CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
hr = CoCreateInstance( CLSID_XMLDocument, NULL, CLSCTX_INPROC_SERVER, IID_IXMLDOMDocument, (void**)&pXML );
At CoCreateInstance it returns E_NOINTERFACE and I cant carry on.
Can someone help ??
Best regards Florian
-
July 13th, 2003, 04:45 PM
#2
The XMLDocument is an older XML parser, you want do create the DOMDocument parser. To do this, change the CLSID from CLSID_XMLDocument to CLSID_DOMDocument.
Also, you mentioned that you were in an MFC app, it might be a good idea to use the AfxOleInit method instead of CoInitializeEx. Directly initializing COM, while it will work, may cause problems for you down the road if you use any of MFC's COM support.
-
July 13th, 2003, 04:59 PM
#3
Originally posted by jmc_mod
The XMLDocument is an older XML parser, you want do create the DOMDocument parser. To do this, change the CLSID from CLSID_XMLDocument to CLSID_DOMDocument.
Also, you mentioned that you were in an MFC app, it might be a good idea to use the AfxOleInit method instead of CoInitializeEx. Directly initializing COM, while it will work, may cause problems for you down the road if you use any of MFC's COM support.
Good call, I so missed that when I read it.
Code:
hr = CoCreateInstance( CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, IID_IXMLDOMDocument, (void**)&pDoc);
-
July 13th, 2003, 05:52 PM
#4
Problem solved.
Now there is something else. When I try to use the loadXML methos i dont know how to create the param BSTR xml_source;
I know, is a little stupid, but please help me with this.
Thenx.
-
July 13th, 2003, 06:05 PM
#5
BSTRs are the typical method used to pass strings around in COM. There are a set of functions for dealing with BSTRS: SysAllocString, SysFreeString, SysAllocStringLen, etc.
Since you are in MFC, the easiest thing to do would be to store it in a CString and then call AllocSysString.
Note: NULL is a valid value for a BSTR, so you should be careful, and never directly assign a BSTR to a CString.
Code:
if ( bstrText == NULL )
strMyCString.Empty( );
else
strMyCString = bstrText;
::SysFreeString( bstrText );
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|