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

Xml.UpdateAttrAt Example #2

Another Xml.UpdateAttrAt 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.UpdateAttrAt('xyz|test[i]',True,'index',sbValue.GetAsString());
      i := i + 1;
    end;

  WriteLn(xml.GetXml());

  //  Output is:

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