TXMLDocumentSaveToStream (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following example uses the SaveToStream function.

Code

procedure Test_SaveToStream;
const
  CFilename = 'file.xml';
var
  LDocument: IXMLDocument;
  LNode: IXMLNode;
  LFileStream: TFileStream;
begin
  LDocument := TXMLDocument.Create(nil);
  LDocument.Active := True;

  { Define document content. }
  LNode := LDocument.CreateNode('TestElement');
  LDocument.DocumentElement := LNode;

  LFileStream := TFileStream.Create(CFilename, fmCreate);
  LDocument.SaveToStream(LFileStream);
  LFileStream.Free;
end;

Uses