TXMLDocumentChildNodes (Object Pascal)

From Appmethod Code Examples
Jump to: navigation, search

Description

This example uses the ChildNodes property.

Code

procedure Test_ChildNodes;
const
  LFilename = 'file.xml'; { Should exist. }
var
  LDocument: IXMLDocument;
  LNodeList: IXMLNodeList;
  LNode: IXMLNode;
  i: Integer;
begin
  LDocument := TXMLDocument.Create(nil);
  LDocument.LoadFromFile(LFilename);

  { Traverse child nodes. }
  LNodeList := LDocument.ChildNodes;
  Writeln('Document has ' + IntToStr(LNodeList.Count) + ' child node(s).');
  for i := 0 to LNodeList.Count - 1 do
  begin
    LNode := LNodeList.Get(i);
    Writeln(LNode.NodeName);
  end;
end;

Uses