Lazarus

Programming => General => Topic started by: BubikolRamios on June 13, 2019, 06:40:06 am

Title: thtmldocument get text nodes
Post by: BubikolRamios on June 13, 2019, 06:40:06 am
Code: Pascal  [Select][+][-]
  1. ...
  2. <a>foo</a><a>foo1</a>
  3. ...
  4.  

something like
pseudocode:
Code: Pascal  [Select][+][-]
  1. TDomNodeList := thtmldocument.GetTextNodes()

would return element list  foo,foo1

Is there something like that ?
Title: Re: thtmldocument get text nodes
Post by: wp on June 13, 2019, 07:27:38 am
A solution without THtmlDocument: https://forum.lazarus.freepascal.org/index.php/topic,43090.msg301176.html#msg301176
Title: Re: thtmldocument get text nodes
Post by: marcov on June 13, 2019, 02:31:08 pm
Afaik this is walking the tree and looking for attribute #text in the dom nodes.  Code in compilelatexchm.pp in the "fpcdocs" repository does something like that.
Title: Re: thtmldocument get text nodes
Post by: BubikolRamios on June 14, 2019, 11:40:08 am
To clarify, I don't need complete text, thtmldocument.TextContent already does that.


Examlple: have a list of elements and modify them inside thtmldocument
Code: Pascal  [Select][+][-]
  1.     domNodeList:= thtmldocument.GetElementsByTagName('img');
  2.     for i := 0 to domNodeList.Count-1 do
  3.     begin
  4.        tdomelement(domNodeList[i]).SetAttribute('src',someString);
  5.     end;
  6.  

so needed something instead of

Code: Pascal  [Select][+][-]
  1. thtmldocument.GetElementsByTagName('img');
  2.  

To get me text elements. need to modify them one by one, by regex replace in place, inside thtmldocument .
TinyPortal © 2005-2018