[Htmlparser-user] how to add new nodes/elements to html source
Brought to you by:
derrickoswald
|
From: Srinivas V. <vip...@ho...> - 2007-06-27 00:25:54
|
Hello All, I am pretty new to Java and was wondering if anyone can help=
me out with my question. I am trying to parse some html source and based o=
n some matching content I should add new nodes elements. For eg: I should b=
e able to add a similar tr and td elements to the existing source but with =
different td values. <tr id=3Dtest> <td id=3Dtest1><b>KEY</b></td> =
<td id=3Dtest1><b>VALUE</b></td> </tr>I am doing something like thi=
s: public class MyVisitor extends NodeVisitor { NodeList nl =3D new No=
deList(); public MyVisitor () { } public voi=
d visitTag (Tag tag) { if ((tag instanceof TableRow)) {=
TagNode tc =3D new TableColumn(); t=
c.setAttribute("id","testvalue",'"'); tc.setAttribute("class",=
"valid",'"'); nl.add(new TextNode("Test3")); tc.s=
etChildren(nl); tc.setEndTag(new TableColumn()); =
System.out.println(tc.toHtml()); =
} } public static void main (String[] args) throws ParserExcept=
ion { Parser parser =3D new Parser ("http://www.yahoo.com"); =
MyVisitor visitor =3D new MyVisitor (); NodeList list =3D par=
ser.parse (null); list.visitAllNodesWith(visitor); } }This prin=
ts: <TD id=3D"testvalue" class=3D"valid">Test3<TD> --> not a closing TD?=
?? Also, how can I modify the current html source, the nodevisitor travels =
? Can someone help!!Cheers,=0A=
Srinivas.
_________________________________________________________________
Make every IM count. Download Windows Live Messenger and join the i=92m Ini=
tiative now. It=92s free.=A0=A0
http://im.live.com/messenger/im/home/?source=3DTAGWL_June07=
|