Search code examples
delphidelphi-7msxmlmsxml6

How to create a TXML Document using MSXML 6.0 in Delphi 7?


MSXML 6.0 didn't exist when Delphi 7 was released. Is it possible to configure Delphi's TXML Document to use MSXML 6.0 instead of the older versions?


Solution

  • Add the below code to a unit name uMSXMLVersion or your name of choice and add it to your projects uses

    {----------------------------------------------------------------------------    
      Set Delphi's XMLDocument to use MSXML v6.0
    
      Usage:  Include unit in project "uses"-list and Delphi will automatically use
              MSXML v6.0 for TXmlDocument.
    -----------------------------------------------------------------------------}
    unit uMSXMLVersion;
    
    interface
    
    implementation
    
    uses ActiveX, MSXML, MSXMLDOM;
    
    function CreateDOMDocumentEx: IXMLDOMDocument;
    const
      CLASS_DOMDocument60: TGUID = '{88D96A05-F192-11D4-A65F-0040963251E5}';
    begin
      Result := nil;
      if CoCreateInstance(CLASS_DOMDocument60, nil, CLSCTX_INPROC_SERVER or
        CLSCTX_LOCAL_SERVER, IXMLDOMDocument, Result) <> S_OK then
      Result := CreateDOMDocument; //call the default implementation
    end;
    
    initialization
      MSXMLDOMDocumentCreate := CreateDOMDocumentEx;
    
    end.