TXMLDocumentRefresh (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following example uses the Refresh function. An XML file is manipulated with 2 variables of type IXMLDocument: one writer and one reader.

Code

procedure Test_Refresh;
var
  LDocumentWr: IXMLDocument;
  LDocumentRd: IXMLDocument;
begin
  { Create an XML file. }
  LDocumentWr := TXMLDocument.Create(nil);
  LDocumentWr.Active := True;
  LDocumentWr.DocumentElement := LDocumentWr.CreateNode('TestElement',
    ntElement);
  LDocumentWr.SaveToFile(DestPath);

  { Load the XML file into memory. Display the XML text. }
  LDocumentRd := TXMLDocument.Create(nil);
  LDocumentRd.LoadFromFile(DestPath);
  Writeln(LDocumentRd.XML.Text);

  { Modify the XML file. }
  LDocumentWr.DocumentElement.Text := 'Update.';
  LDocumentWr.SaveToFile(DestPath);

  { Refresh the image of XML file in memory.
    The XML text should contain the word 'Update'. }
  LDocumentRd.Refresh;
  Writeln('Refreshing...' + sLineBreak);
  Writeln(LDocumentRd.XML.Text);
end;

Uses