Parsing html tag
lazarus / 38-Networking and Web Programming
----------------------------------------------------------------------
gadido30 · 2013-12-31 12:22
Hi All,
I am new in Lazarus and I don't know if it was asked before,
I have a meta tag of html in AnsiString:
test
What is the best way to parse it into strings or items?
I did try DOM , but it say its AnsiString
Thank You
Gadi
----------------------------------------------------------------------
Leledumbo · 2013-12-31 13:43
http://benibela.de/sources_en.html#internettools
or with the builtin libraries:
Code: [Select]{$mode objfpc}
uses classes,dom,xmlread;
var
s: TStringStream;
d: TXMLDocument;
n: TDOMNode;
i: Integer;
begin
try
d := nil;
s := TStringStream.Create('test');
ReadXMLFile(d,s);
if Assigned(d) then begin
n := d.FirstChild;
WriteLn('Name: ' + n.NodeName);
if Assigned(n.Attributes) then begin
WriteLn('Attributes:');
for i := 0 to n.Attributes.Length - 1 do
WriteLn('- ' + n.Attributes[i].NodeName + ' = ' +
n.Attributes[i].NodeValue);
WriteLn('Text: ' + n.NodeValue);
end;
end else WriteLn(StdErr,'Reading failed');
finally
if Assigned(d) then d.Free;
if Assigned(s) then s.Free;
end;
end.