Let's say all your page is a set of two nodes, the <HEAD></HEAD> node and the <BODY></BODY> node, which you got from your NodeIterator and put into a NodeList as element zero and element one.
To remove all the body, use:
Tag body = nodelist.elementAt (1);
body.removeAll ();
To add a string like
hello world
where world is bolded, use:
body.add (new StringNode ("hello "));
Tag b = new Tag ();
b.setTagName ("B"); // bold
body.add (b);
body.add (new StringNode ("world");
Tag no_b = new Tag ();
no_b.setTagName ("/B"); // not bold
body.add (no_b);
Like I said, it's not really good at it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry,
the line
Tag body = nodelist.elementAt (1);
should be
NodeList body = nodelist.elementAt (1).getChildren ();
so all the operations are on the children of the <BODY></BODY> node.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Is it is possible to delete and replace the content of html file using the HTML parser. If possible using which class. How?
The HTML Parser doesn't really handle the synthesis use-case very well (see http://htmlparser.sourceforge.net/\), but here goes.
Let's say all your page is a set of two nodes, the <HEAD></HEAD> node and the <BODY></BODY> node, which you got from your NodeIterator and put into a NodeList as element zero and element one.
To remove all the body, use:
Tag body = nodelist.elementAt (1);
body.removeAll ();
To add a string like
hello world
where world is bolded, use:
body.add (new StringNode ("hello "));
Tag b = new Tag ();
b.setTagName ("B"); // bold
body.add (b);
body.add (new StringNode ("world");
Tag no_b = new Tag ();
no_b.setTagName ("/B"); // not bold
body.add (no_b);
Like I said, it's not really good at it.
Sorry,
the line
Tag body = nodelist.elementAt (1);
should be
NodeList body = nodelist.elementAt (1).getChildren ();
so all the operations are on the children of the <BODY></BODY> node.