Class TXMLElementIterator

DescriptionHierarchyFieldsMethodsProperties

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;
  try
    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;
  finally FreeChildNodes(ChildrenList); 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 := TXMLElementIterator.Create(Element);
  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 destructor Destroy; override;
Public function GetNext: boolean; virtual;

Properties

Public property Current: TDOMElement read FCurrent;

Description

Methods

Public constructor Create(ParentElement: TDOMElement);
 
Public destructor Destroy; override;
 
Public function GetNext: boolean; virtual;
 

Properties

Public property Current: TDOMElement read FCurrent;
 

Generated by PasDoc 0.14.0.