Class TXMLElementIterator

Unit

Declaration

type TXMLElementIterator = class(TObject)

Description

Iterate over all children elements of given XML element.

Without this, typical iteration looks like

var
  Index: Integer;
  ChildrenList: TDOMNodeList;
  ChildNode: TDOMNode;
  ChildElement: TDOMElement;
begin
  ChildrenList := Element.ChildNodes;

  for Index := 0 to ChildrenList.Count - 1 do
  begin
    ChildNode := ChildrenList.Item[Index];
    if ChildNode.NodeType = ELEMENT_NODE then
    begin
      ChildElement := ChildNode as TDOMElement;
      ... here goes your code to process ChildElement ...
    end;
  end;
end;

... which is an easy code, but it becomes tiresome to write this over and over again, especially for units that heavily process XML (like X3D XML or Collada readers). So this class allows you to write instead

var
  I: TXMLElementIterator;
begin
  I := Element.ChildrenIterator;
  try
    while I.GetNext do
    begin
      ... here goes your code to process I.Current ...
    end;
  finally FreeAndNil(I) end;
end;

Hierarchy

  • TObject
  • TXMLElementIterator

Overview

Methods

Public constructor Create(ParentElement: TDOMElement);
Public function GetNext: boolean; virtual;
Public procedure Rewind;
Public function Count: Integer;

Properties

Public property Current: TDOMElement read FCurrent;

Description

Methods

Public constructor Create(ParentElement: TDOMElement);
 
Public function GetNext: boolean; virtual;
 
Public procedure Rewind;
 
Public function Count: Integer;
 

Properties

Public property Current: TDOMElement read FCurrent;
 

Generated by PasDoc 0.16.0.