[Htmlparser-user] Changing the HTML code
Brought to you by:
derrickoswald
From: Lucas S. <lsa...@gm...> - 2007-10-20 14:03:36
|
Hello everyone. It seems a simple task, but I couldn't figure out how to do it yet. What I want to do is to get an HTML code from a database and check if all the images path and link path are relative ou absolute, if they are relative I'll turn then to absolute. So an <a href="test.html"> would become a <a href="http://www.marx.com.br/test.html">. So tried to do it on two ways: 1 - First way I first created the parse: Parser parse = new Parser(); parse.setInputHTML(html.toString()); Where the html variable is a StringBuffer. After it I created an filter and searched for it on the parse: NodeFilter filtro = new NodeClassFilter(LinkTag.class); lista = parse.extractAllNodesThatMatch(filtro); So than I iterated into the lista variable and changed the link: aux = link.getLink(); if (aux != null && aux.indexOf("http://") == -1){ aux = "http://www.marx.com.br/" + aux; } link.setLink(aux); 2 - Second way I did the samething of the first way, but besides getting all the link, I created a NodeVisitor which checks it the tag is an link and change its and I called the method parse.visitAllNodesWith(visitante); Until this place is everything working just fine, my problem is how to retrieve the final html which I have changed? Thanks, -- Lucas Sanabio ----------------------------------------------------------------------------- Sun Certified Programmer for the Java 2 Platform Consultor Java - Marx Tecnologia URL: http://www.marx.com.br Email: lu...@ma... Tel: (62) 3281-9889 ou (62) 8117-5266 |