Parse XML, extract all elements, attributes and included data.

 
The provided demo parses an XML document that is provided within Delphi string list, extracts all tags, tag attributes and included data.
 
procedure TForm1.Button1Click(Sender: TObject);
var
  i, j: Integer;
begin
  clHtmlParser1.Parse(Memo1.Lines);
 
  Memo2.Lines.Clear();
 
  for i := 0 to clHtmlParser1.Tags.Count - 1 do
  begin
    if (not clHtmlParser1.Tags[i].IsText) and (clHtmlParser1.Tags[i].Name <> '!--') then
    begin
      Memo2.Lines.Add(clHtmlParser1.Tags[i].Name);
 
      for j := 0 to clHtmlParser1.Tags[i].AttributeCount - 1 do
      begin
        Memo2.Lines.Add(#9 + clHtmlParser1.Tags[i].Attributes[j].Name + ':' + clHtmlParser1.Tags[i].Attributes[j].Value);
      end;
 
      if (clHtmlParser1.Tags[i].NextTag <> nil)
        and (clHtmlParser1.Tags[i].NextTag.IsText)
        and (clHtmlParser1.Tags[i].NextTag.Owner <> clHtmlParser1.Tags[i].Owner)
        and (Trim(clHtmlParser1.Tags[i].Text) <> '') then
      begin
        Memo2.Lines.Add(#9'Data:' + clHtmlParser1.Tags[i].Text);
      end;
    end;
  end;
 
  ShowMessage('Done');
end;

Add Feedback