[Htmlparser-user] Change Attributes of TDs and TRs
Brought to you by:
derrickoswald
From: Fuhrmann, M. <mic...@sa...> - 2006-01-11 13:26:16
|
Hi All! I want to change several attributes of the td and tr tags of certain = tables but I don't know if do it the right way. The problem is that I find the right table (only tables with ids) but I = don't reach the td or tr tags.... My code looks like that: public void cleanDokument(HttpServletRequest request,HttpServletResponse = response) throws IOException {=09 // Get the calling HTML Document define the Writer and open the = connection URLConnection connection; URL request_url =3D new URL(request.getHeader("referer").toString()); PrintWriter out =3D response.getWriter(); connection =3D (HttpURLConnection)request_url.openConnection (); =09 try { Parser parser =3D new Parser (); parser.setConnection(connection); =20 NodeFilter all_tables =3D new TagNameFilter("table"); NodeList list =3D parser.parse (all_tables); Node[] nodelist; // Seperate all table tags for (NodeIterator e =3D parser.elements (); e.hasMoreNodes ();) e.nextNode ().collectInto (list,all_tables); =20 nodelist=3Dlist.toNodeArray(); =20 for (int h=3D0; h<nodelist.length;h++)=20 { if (nodelist[h] instanceof TableTag)=20 {=09 //for schleife f=FCr die td's und tr's=09 if(((TableTag)nodelist[h]).getAttribute("id")!=3D null)=20 { for (int i=3D0; i<nodelist.length; i++) { out.println(nodelist.toString()); if(nodelist[i] instanceof TableRow) { out.println("Row found!"); ((TableRow)nodelist[i]).removeAttribute ("nowrap"); } else if (nodelist[i] instanceof TableColumn) { out.println("Column found!"); ((TableColumn)nodelist[i]).removeAttribute ("nowrap"); } } out.println(nodelist[h].toHtml()); } } else if(nodelist[h] instanceof TableRow || nodelist[h] instanceof = TableColumn) { out.println("Else erreicht!"); out.println(((TableRow)nodelist[h]).getText()); } } //makePdf(out,response); } catch(Exception e) { out.println("Fehler beim Parsen!"); e.printStackTrace(out); } } Does my nodelist contain the tr and td tags? Is it right to say = instanceof TableRow???? Many thanks and best regards Michael |