Joe
Joe

Reputation: 3015

Save a IXMLDOMDocument3 to xml-file in runtime with Delphi 2007

If I would like to save a IXMLDOMDocument3 in runtime to a file on my harddrive, what is the syntax for that?

E.g. like IXMLDOMDocument3.save('c:\test.xml')

Or is it even possible?

Best regards!

Upvotes: 1

Views: 2177

Answers (1)

teran
teran

Reputation: 3234

the sample code below demonstrates how to load and save IXMLDomDocument3 XML at runtime. It uses msxml header file from Delphi-2010. IXMLDomDocument3 inherits from IXMLDomDocument and has Save method (as you wrote in your question). If method parameter is a string, then it specifies file name (it creates or replaces target file).

program Project3;
{$APPTYPE CONSOLE}

uses SysUtils, msxml, comObj, activex;

    procedure LoadAndSaveXML(LoadFile, SaveFile : string);
    var xml : IXMLDOMDocument3;
        tn : IXMLDOMElement;
    begin
        xml := CreateComObject(CLASS_DOMDocument60) as IXMLDOMDocument3;
        xml.load(LoadFile);
        xml.save(SaveFile);
    end;
begin
  try

    CoInitialize(nil);
    try
        LoadAndSaveXML('D:\in.xml', 'D:\out.xml');
    finally
        CoUninitialize();
    end;
  except
    on E: Exception do begin
      Writeln(E.ClassName, ': ', E.Message);
      readln;
    end;
  end;
end.

Upvotes: 4

Related Questions