Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Load MIME from XML
See more MIME Examples
Demonstrates the Chilkat Mime.LoadXml method, which reconstructs a MIME tree from Chilkat's MIME XML. The only argument is the XML string.
Background: Chilkat can represent a MIME tree as XML — headers as elements, parameters as attributes — which is convenient for inspecting or editing structure with XML tools. This is the inverse of
GetXml: it rebuilds the full MIME object from that representation. Invalid XML leaves the current object unchanged.Chilkat Pascal (Lazarus/Delphi) Downloads
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.Mime;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
mime: TMime;
xmlText: string;
begin
success := False;
// Demonstrates the Mime.LoadXml method, which reconstructs a MIME tree from Chilkat's MIME XML.
// The only argument is the XML string.
mime := TMime.Create;
// Chilkat MIME XML (as produced by GetXml).
xmlText := '<mime><contentType>text/plain</contentType><body>Hello.</body></mime>';
success := mime.LoadXml(xmlText);
if (success = False) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
WriteLn('Content-Type: ' + mime.ContentType);
mime.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.