htmlParser rewrite HTML

Yesteday, I have tried many methods to rewrite HTML.
And find TagNode can not write TextNode, so if I want to replace “<p> id=”hello”></p>” to “<p id=”hello”>it’s me</p>”. There is no method to support. And in htmlParser, there is a method call setText(). But setText is only set text into<p id=”hello”>, like “<p id=”hello” class=”pp”>”. The method can not write text into”<p></p>”. If you want to add a TextNode as TagNode child. HtmlParser can not support this idea also. Like:

NodeList nl = p.parse(null);
NodeVisitor nv = new NodeVisitor(){
public void visitTag(Tag tag) {
if (tag instanceof ParagraphTag) {
String attribute = tag.getAttribute(“id”);
if (attribute == null){
TextNode tn = new TextNode(tag.getText());
tn.setText(“sidafnaf “);
Text t = new TextNode(“abc”);
// It does not work
NodeList temp = new NodeList();
} else if (tag.getAttribute(“id”).equals(“author”)){
tag.setAttribute(“innerHTML”,”id a”);
} else if (tag instanceof LinkTag){
if (tag.getAttribute(“id”).equals(“come-from”)){
// can write an attribute innerHtml = “ok?”
// can rewrite URL attribute
tag.setAttribute(“href”, ““);

Solve this problem, you should flag where you want to insert. like<p>messgae</p>
Then use following code:

NodeList nl = p.parse(null);
NodeVisitor nv = new NodeVisitor(){
public void visitStringNode(Text string){
string.setText(“It’s me”);
// if you want change attributes of <p>
TagNode tn = string.getParent();

Now it’s done.