Hi
I want to add an attribute to each tag in a html document. I have
written a nodevisitor to do that and it works. However, for some
documents, I get a StackOverflowError when I want to output the html
back. Here is my code.
public class TestHTMLParser
{
public static void main(String args[]) throws Exception
{
Parser p = new Parser("http://lemonde.fr");
NodeList nliste = p.parse(null);
NodeIterator ni = nliste.elements();
MyNodeVisitor mynv = new MyNodeVisitor();
while (ni.hasMoreNodes())
{
Node n = ni.nextNode();
if (n instanceof Html)
n.accept(mynv);
}
System.out.println(nliste.toHtml());
}
}
public class MyNodeVisitor extends NodeVisitor {
public MyNodeVisitor() {
super();
}
public void visitTag(Tag tag){
tag.setAttribute("onClick", "return false;");
}
}
If I don't use the nodevisitor, I don't get the StackOverflowError.
So is it normal (my html tree has become too deep after the attributes
add) or is there a bug ?
Thanks for help.
|