unit MSXMLDom4;
// To use MSXML 4.0 it is sufficient to add this unit to your project

// Copyright (c) 2001 Information Dynamics
// Author: Martijn Houtman
// Email: Delphi@MartijnHoutman.com

// Vincent Parret gave a tip for writing this unit

// This software is free and no registration is required

interface

implementation

uses
  Windows, ActiveX, ComObj, msxml, xmldom, msxmldom;

// copied from xmldom.pas
resourcestring
  SMSDOMNotInstalled = 'Microsoft MSXML is not installed';

const
  { GUID's from MSXML2_TLB.pas }
  CLASS_DOMDocument26: TGUID = '{F5078F1B-C551-11D3-89B9-0000F81FE221}';
  CLASS_DOMDocument30: TGUID = '{F5078F32-C551-11D3-89B9-0000F81FE221}';
// new MSXML 4.0 class
  CLASS_DOMDocument40: TGUID = '{88D969C0-F192-11D4-A65F-0040963251E5}';


// copied from xmldom.pas
function TryObjectCreate(const GuidList: array of TGuid): IUnknown;
var
  I: Integer;
  Status: HResult;
begin
  for I := Low(GuidList) to High(GuidList) do
  begin
    Status := CoCreateInstance(GuidList[I], nil, CLSCTX_INPROC_SERVER or
      CLSCTX_LOCAL_SERVER, IDispatch, Result);
    if Status = S_OK then Break;
    if Status <> REGDB_E_CLASSNOTREG then
      OleCheck(Status);
  end;
end;

// copied from xmldom.pas and added CLASS_DOMDocument40
function CreateDOMDocument: IXMLDOMDocument;
begin
  Result := TryObjectCreate([CLASS_DOMDocument40, CLASS_DOMDocument30, CLASS_DOMDocument26,
    msxml.CLASS_DOMDocument]) as IXMLDOMDocument;
  if not Assigned(Result) then
    raise DOMException.Create(SMSDOMNotInstalled);
end;

initialization
  MSXMLDOMDocumentCreate := CreateDOMDocument;
end.
