Re: [Htmlparser-user] how to add new nodes/elements to html source
Brought to you by:
derrickoswald
From: Derrick O. <der...@ro...> - 2007-06-27 02:27:23
|
Srinivas,=0A=0ATry:=0A=0ATableColumn end =3D new TableColumn ();=0Aend.setT= agName ("/TD");=0A=0AYou can modify the current html, but carefully so the = visiting logic doesn't get into an infinite loop.=0ALike, don't add a node = after the current node in the parent's children.=0AYou will need to gather = it all first, like you are doing:=0A=0AParser parser =3D new Parser ("http:= //www.yahoo.com");=0ANodeList content =3D parser.parse (null);=0A=0Athen ap= ply your visitor:=0A=0Acontent.visitAllNodesWith (my_visitor);=0A=0Athen ma= ke it into html again:=0A=0AString s =3D content.toHtml ();=0A=0A=0ADerrick= =0A=0A----- Original Message ----=0AFrom: Srinivas Vippagunta <vippagunta@h= otmail.com>=0ATo: htm...@li...=0ASent: Tuesday, Ju= ne 26, 2007 8:25:47 PM=0ASubject: [Htmlparser-user] how to add new nodes/el= ements to html source=0A=0A=0A=0A=0AP=0A{=0Amargin:0px;padding:0px;}=0Abody= =0A{=0AFONT-SIZE:10pt;FONT-FAMILY:Tahoma;}=0A=0AHello All,=0A I am pret= ty 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 on some matching content = I should add new nodes elements. For eg: I should be able to add a similar = tr and td elements to the existing source but with different td values.=0A= =0A=0A <tr id=3Dtest>=0A <td id=3Dtest1><b>KEY</b></td>=0A <td = id=3Dtest1><b>VALUE</b></td>=0A </tr>=0A=0A=0AI am doing something like= this: =0A=0A public class MyVisitor extends NodeVisitor=0A {=0A NodeLi= st nl =3D new NodeList(); =0A =0A public MyVisitor ()=0A {= =0A }=0A =0A public void visitTag (Tag tag)=0A {=0A = if ((tag instanceof TableRow))=0A { =0A=0A = TagNode tc =3D new TableColumn();=0A tc.setAttribute("id","t= estvalue",'"');=0A tc.setAttribute("class","valid",'"');=0A = nl.add(new TextNode("Test3"));=0A tc.setChildren(nl= );=0A tc.setEndTag(new TableColumn()); =0A = =0A System.out.println(tc.toHtml());=0A =0A = }=0A=0A=0A }=0A=0A public static void main (String[] args) th= rows ParserException=0A {=0A Parser parser =3D new Parser ("htt= p://www.yahoo.com");=0A MyVisitor visitor =3D new MyVisitor ();=0A = NodeList list =3D parser.parse (null);=0A list.visitAllNode= sWith(visitor);=0A }=0A }=0A=0AThis prints: <TD id=3D"testvalue" class= =3D"valid">Test3<TD> --> not a closing TD??? =0A=0AAlso, how can I modif= y the current html source, the nodevisitor travels ? =0A=0ACan someone help= !!=0A=0A=0ACheers,=0A=0ASrinivas.=0A=0AMake every IM count. Download Window= s Live Messenger and join the i=A2m Initiative now. It=A2s free. Make it c= ount!----------------------------------------------------------------------= ---=0AThis SF.net email is sponsored by DB2 Express=0ADownload DB2 Express = C - the FREE version of DB2 express and take=0Acontrol of your XML. No limi= ts. Just data. Click to get it now.=0Ahttp://sourceforge.net/powerbar/db2/= =0A_______________________________________________=0AHtmlparser-user mailin= g list=0AH...@li...=0Ahttps://lists.sourceforge.= net/lists/listinfo/htmlparser-user=0A=0A=0A=0A=0A |