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

Xml.ChildContent Example #2

Another Xml.UpdateChildContent example...

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.StringBuilder,
  Chilkat.Xml;

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

procedure RunDemo;
var
  xml: TXml;
  sbValue: TStringBuilder;
  i: Integer;

begin
  xml := TXml.Create;
  xml.Tag := 'abc';

  sbValue := TStringBuilder.Create;

  i := 0;
  while i < 10 do
    begin
      xml.I := i;
      sbValue.Clear();
      sbValue.AppendInt(i);
      xml.UpdateChildContent('xyz|test[i]',sbValue.GetAsString());
      i := i + 1;
    end;

  WriteLn(xml.GetXml());

  //  Output is:

  //  	<?xml version="1.0" encoding="utf-8" ?>
  //  	<abc>
  //  	    <xyz>
  //  	        <test>0</test>
  //  	        <test>1</test>
  //  	        <test>2</test>
  //  	        <test>3</test>
  //  	        <test>4</test>
  //  	        <test>5</test>
  //  	        <test>6</test>
  //  	        <test>7</test>
  //  	        <test>8</test>
  //  	        <test>9</test>
  //  	    </xyz>
  //  	</abc>


  xml.Free;
  sbValue.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.