Which version of MSXML should I use?

前端 未结 5 1907
Happy的楠姐
Happy的楠姐 2020-11-30 01:40

Seems like this would be a common question, though I could not find it on SO.

Which version of MSXML should I use in my applications, and more importantly,

5条回答
  •  暖寄归人
    2020-11-30 02:17

    I had to make the same decision in my work a couple of years ago.

    The MSDN states that version 6 is the optimal one to use, however they don't provide merge modules in the SDK and you are not allowed to distribute it in your application as you could with version 4. Version 4 was superceded by version 6 and version 5 was specifically for MS Office. Version 3 remains the target version on older machines.

    What I ended up doing was taking a graceful degradation approach and attempting to use 6 first, failing that version 4, then failing that use version 3 (code is C++):

    inline bool CXMLDocument::CreateXMLDOMFactory(void)
    {
        wxMutexLocker lock(sm_mXMLDOMFactory);
    
        if(!sm_pXMLDOMFactory)
        {
            ::CoGetClassObject(CLSID_DOMDocument60, CLSCTX_ALL, 0, IID_IClassFactory, reinterpret_cast(&sm_pXMLDOMFactory));
            if(!sm_pXMLDOMFactory)
            {
                ::CoGetClassObject(CLSID_DOMDocument40, CLSCTX_ALL, 0, IID_IClassFactory, reinterpret_cast(&sm_pXMLDOMFactory));
                if(!sm_pXMLDOMFactory)
                    ::CoGetClassObject(CLSID_DOMDocument30, CLSCTX_ALL, 0, IID_IClassFactory, reinterpret_cast(&sm_pXMLDOMFactory));
            }
        }
    
        return sm_pXMLDOMFactory != 0;
    }
    

    We noticed measurable performance improvements after moving to version 6 from version 4, although you have to explicitly set the NewParser property on the document to get this benefit, e.g.:

    pDocument->setProperty(_bstr_t(L"NewParser"), VARIANT_TRUE);
    

    There were also a couple more hoops to jump through when loading documents due to security considerations, remote DTDs and so on. Again, this was done via properties on the document, so it is worth looking up the ProhibitDTD, UseInlineSchema, AllowXsltScript and ServerHTTPRequest properties in the MSDN to see if they apply to your usage.

提交回复
热议问题