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

Download HTML from URL and Convert to XML

See more HTML-to-XML/Text Examples

Downloads an HTML page from a URL and converts it to 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.Global,
  Chilkat.HtmlToXml,
  Chilkat.Http;

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

procedure RunDemo;
var
  success: Boolean;
  glob: TGlobal;
  http: THttp;
  html: string;
  htmlToXml: THtmlToXml;
  xml: string;

begin
  success := False;

  //  Note: This example requires the Chilkat Bundle license.

  //  Any string argument automatically begins the 30-day trial.
  glob := TGlobal.Create;
  success := glob.UnlockBundle('30-day trial');
  if (success <> True) then
    begin
      WriteLn(glob.LastErrorText);
      Exit;
    end;

  http := THttp.Create;

  html := http.QuickGetStr('http://www.intel.com/');
  if (http.LastMethodSuccess <> True) then
    begin
      WriteLn(http.LastErrorText);
      Exit;
    end;

  htmlToXml := THtmlToXml.Create;

  //  Indicate the charset of the output XML we'll want.
  htmlToXml.XmlCharset := 'utf-8';

  //  Set the HTML:
  htmlToXml.Html := html;

  //  Convert to XML:

  xml := htmlToXml.ToXml();

  //  Save the XML to a file.
  //  Make sure your charset here matches the charset
  //  used for the XmlCharset property.
  success := htmlToXml.WriteStringToFile(xml,'qa_output/out.xml','utf-8');

  WriteLn('Finished.');


  glob.Free;
  http.Free;
  htmlToXml.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.