CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2002
    Location
    Romania
    Posts
    24

    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

  2. #2
    Join Date
    Jul 2003
    Posts
    30
    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.

  3. #3
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    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);

  4. #4
    Join Date
    Oct 2002
    Location
    Romania
    Posts
    24
    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.

  5. #5
    Join Date
    Jul 2003
    Posts
    30
    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
  •  





Click Here to Expand Forum to Full Width

Featured