Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
XML GetChildWithAttr
See more XML Examples
Demonstrates how to get the content of a particular node with a particular attribute. For example, returns "Face up in the Rain" for the Name="Album" node.<Response Status="OK"> <Item Name="ZoneID">0</Item> <Item Name="State">2</Item> <Item Name="FileKey">305718</Item> <Item Name="Artist">Michael Tomlinson</Item> <Item Name="Album">Face Up in the Rain</Item> <Item Name="Name">The Way We're Going</Item> <Item Name="Status">Playing</Item> </Response>
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.Xml;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
xml: TXml;
xItem: TXml;
begin
success := False;
xml := TXml.Create;
success := xml.LoadXmlFile('qa_data/resp.xml');
if (success <> True) then
begin
WriteLn(xml.LastErrorText);
Exit;
end;
xItem := xml.GetChildWithAttr('Item','Name','Album');
if (xml.LastMethodSuccess = False) then
begin
WriteLn('not found.');
Exit;
end;
WriteLn(xItem.Content);
xItem.Free;
xml.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.