Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Load XML from a Remote URL

Demonstrates how to load XML from a remote URL, such as https://www.chilkatsoft.com/hamlet.xml

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Http,
  Chilkat.StringBuilder,
  Chilkat.Xml;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  http: THttp;
  sbXml: TStringBuilder;
  xml: TXml;

begin
  success := False;

  //  This example assumes the Chilkat HTTP API to have been previously unlocked.
  //  See Global Unlock Sample for sample code.

  http := THttp.Create;
  sbXml := TStringBuilder.Create;

  //  Download the XML from the URL into sbXml
  success := http.QuickGetSb('https://www.chilkatsoft.com/hamlet.xml',sbXml);
  if (success = False) then
    begin
      WriteLn(http.LastErrorText);
      Exit;
    end;

  xml := TXml.Create;

  //  Load the XML contained in sbXml
  success := xml.LoadSb(sbXml,True);
  if (success = False) then
    begin
      WriteLn(xml.LastErrorText);
      Exit;
    end;

  WriteLn('Success.');


  http.Free;
  sbXml.Free;
  xml.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.