remove elements from dynamically generated html page
Hi all,
need some help...
Here is my issue..
String msg = xxxx.getHtml(xxId, yyy, ...);
Here Iam getting the html page into some String (msg).
(That html page is dynamically generated ,but there are few elements,
Now i want to remove those few elements from that html resource and again i want to store that new html in to some new String (msg2)..so that i can pass that new modified html to some other method(mailing method).
abc.mailHtml(msg2, subject, from , to);
can any body help me out ...
Thanks in advance
[592 byte] By [
koochi] at [2007-11-11 8:50:59]

# 1 Re: remove elements from dynamically generated html page
Since you have stored your html in a string, you only can do stringprocessing, eg string replace. You also could build your html within a dom-tree, like xml. i think there are several opensource apis that can do that. in a dom tree you can iterate through the diferent nodes, which will represent your tags.
but back to the string approach: expecting your html fragment to be sth like
<html><header><title>xxx</title></header><body><h1>hello world</h1></body></html>
and you would like to replace the "<h1>hello world</h1>" part, then you could apply the following replacement:
msg1.replace("<h1>hello world</h1>", "test");
if you don't know the automatically generated content, you could use the tags surrounding the corresponding data and use regex:
msg1.replace("<h1>.*?</h1>", "test");
you also can apply more complex regex with multiline match and ignoring case by using the pattern and matcher classes.