uses
htmlutil;
type
TCell = string;
TRow = array of TCell;
TTableRec = record
row: array of TRow;
end;
var
InTable, InCell, InRow: boolean;
RowCount, ColCount, TableCount: longword;
TableRec: TTableRec;
type
TClass = class
procedure OnTag...
procedure OnText...
procedure Parse...
end;
procedure TClass.Parse;
var
parser: TFastHtmlParser;
const
HTMLSTRING= 'SOME HTML <TABLE> <TR><TD>blah</TD></TR></TABLE>';
begin
parser:= TFastHtmlParser.create(HTMLSTRING);
parser.OnTag:= @self.Ontag;
parser.OnText:= @self.OnText;
parser.exec;
parser.free;
end;
procedure TClass.OnTag(UpcaseTag: string);
begin
if htmlutil.GetTagName(UpcaseTag) = 'TABLE' then
begin
InTable = true;
inc(tablecount);
rowcount:= 0;
colcount:= 0;
end;
if htmlutil.GetTagName(UpcaseTag) = 'TR' then
begin
InRow = true;
inc(rowcount);
colcount = 0 ;
end;
if htmlutil.GetTagName(UpcaseTag) = 'TD' then
begin
incell = true;
inc(colcount);
end;
if UpcaseTag = '</TD>' then
incell:= false;
if UpcaseTag = '</TR>' then
inrow:= false;
if UpcaseTag = '</TABLE>' then
intable:= false;
end;
procedure TClass.OnText(text: string);
var tmp: string;
begin
if InTable then
if InCell then
begin
tmp:= tablerec.row[rowcount][colcount];
tablerec.row[rowcount][colcount] := tmp + text;
end;
end;
|