3

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?

neves
  • 33,186
  • 27
  • 159
  • 192

2 Answers2

10

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.
Flynn1179
  • 11,925
  • 6
  • 38
  • 74
Fritz Deelman
  • 273
  • 2
  • 7
  • Nice trick to reassign a function. I didn't know you could this dynamic language trick in Delphi. Even better than this is that the guys that created the legacy code I'm working on also didn't know the trick :-) – neves Sep 12 '11 at 03:26
  • [Fatal Error] uMSXMLVersion.pas(13): File not found: 'MSXML.dcu' in Delphi 7 Personal Edition. What am I missing? – Slappy Jul 27 '16 at 07:20
9

The msxmldom.pas unit exposes a public MSXMLDOMDocumentCreate hook that you can assign a custom handler to, eg:

uses
  ..., msxmldom;

const
  CLASS_DOMDocument60: TGUID = '{88D96A05-F192-11D4-A65F-0040963251E5}';

function CreateMSXML6Document: IXMLDOMDocument;
var
  Disp: IDispatch;
begin
  OleCheck(CoCreateInstance(CLASS_DOMDocument60, nil, CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER, IDispatch, Disp));
  Result := Disp as IXMLDOMDocument;
  if not Assigned(Result) then
    raise DOMException.Create('MSXML 6.0 Not Installed');
end;

initialization
  msxmldom.MSXMLDOMDocumentCreate := CreateMSXML6Document;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 1
    Thanks for your answer. I really think your code is little better than the one from Fritz Deelman, but he answered before. – neves Sep 12 '11 at 03:24