aspose file tools*
The moose likes Java in General and the fly likes Navigating through the HTML table using code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

Navigating through the HTML table using code

Sridhar Venkataraman
Ranch Hand

Joined: May 22, 2006
Posts: 76
Say I have a HTML table rendered onto a web page with a certain number of rows and columns. Is it possible to "navigate" through the table (i.e. to particular row-column intersections [cells]) using code? Can someone please give me a sample?

Thanks a ton!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19784
    
  20

The javax.swing.text.html and javax.swing.text.html.parser packages can help you out a bit.

Basically, you'll need a parser, and a callback to handle what you encounter:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
This may get thrown out of the beginner forum, but for a real mind blower, see the Parse class in the FIT testing tool. It parses an HTML table into a graph of objects in only a few lines.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Sridhar Venkataraman
Ranch Hand

Joined: May 22, 2006
Posts: 76
I had no idea how difficult this is to do with Java. I have to do this in a web application using JSP.

What is the FIT testing tool? I am totally uninitiated!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

So I take it you are doing some screen scraping? Cannot you negotiate with your data provider to get the information in a more digestible format? HTML is a display format so it's not surprising that it's difficult to try and use it as a data format.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8883
    
    5
as predicted, this is SO getting thrown out of the beginner's forum


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Sridhar Venkataraman
Ranch Hand

Joined: May 22, 2006
Posts: 76
Thanks for the move and the replies..

I actually have asked this question because it is the only idea I got in my head in relation to solving the *big* dilemma I posted here. Any help there will be appreciated whole-heartedly!

http://www.coderanch.com/t/292896/JSP/java/Seating-arrangement-application-JSP-Struts
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I followed up in the other thread. I think you need to generate HTML, not parse it. Does that sound right?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Navigating through the HTML table using code