Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Set a MIME Body from XML
See more MIME Examples
Demonstrates the Chilkat Mime.SetBodyFromXml method, which sets the body as XML, changes the media type to text/xml, and selects an appropriate transfer encoding. The only argument is the XML text.
Background: This produces an XML-typed part, common in machine-to-machine messaging — SOAP, AS2/EDI payloads, structured data attachments. Marking the content
text/xml lets the receiver route and parse it correctly, and Chilkat picks a transfer encoding that preserves the XML across the transport.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;
xml: string;
begin
success := False;
// Demonstrates the Mime.SetBodyFromXml method, which sets the body as XML and changes the media
// type to text/xml. The only argument is the XML text.
mime := TMime.Create;
xml := '<note><to>Bob</to><from>Alice</from><body>Hello</body></note>';
success := mime.SetBodyFromXml(xml);
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.