I'm trying to replace all text in between tags and I want to know the fastest way of doing so.
An example would be trying to replace all text with the arbitrary string helloWorld, so that this:
<div>
<div>
RandomText1
<div>
RandomText2
</div>
</div>
</div>
Becomes this:
<div>
<div>
helloWorld
<div>
helloWorld
</div>
</div>
</div>
My current approach would be :
- Do Depth-first search (DFS) on DOM
- For each element parse and determine which part is text and which part is an element.
- For the part that is text replace it.
This to me would be really slow, especially trying to do this for a large document and having to repeat the process many times. Is there a faster way?
TreeWalker
. – CertainlynodeIterator
– Emptyheaded