I need to collect each respective value from each row.
Any help would be much appreciated :)
Piyush Mangal
Ranch Hand
Joined: Jan 22, 2007
Posts: 196
posted
0
You can make use of any available Java Script libraries like JQuery, Prototype for this.
Gary Sheldon
Ranch Hand
Joined: Nov 21, 2011
Posts: 44
posted
0
I am pulling the raw data from a database put need to parse and populate another set of tables. Could you please provide an example?
Tim Moores
Rancher
Joined: Sep 21, 2011
Posts: 2407
posted
0
jQuery and such libraries will only help if the HTML is part of a web page inside a browser, not so much in your case.
Libraries such as NekoHTML, HtmlCleaner, jTidy and TagSoup clean up HTML and transform it to XML - thus enabling the use of XML APIs such as DOM and XPath.
Gary Sheldon
Ranch Hand
Joined: Nov 21, 2011
Posts: 44
posted
0
So in essence, I need to pass the database stored html string to a library to translate to XML and then parse that?
Gary Sheldon
Ranch Hand
Joined: Nov 21, 2011
Posts: 44
posted
0
Please help I am batting my head against a brick wall, could anyone please provide a real world demo example?
Gary Sheldon
Ranch Hand
Joined: Nov 21, 2011
Posts: 44
posted
0
What about the posibility, for example:
1. Find how many table rows <tr> exist in the string
2. Split the string at </tr>
3. Move to first stringbetween <td> </td>
4. Get value
5. Move to next stringbetween <td> </td>
6. Repeat 4
7. Repeat 4 &5 till end of the row
8. Repeat 3 to 7 for each row.
Just a thought, the html is well formatted.
Tim Moores
Rancher
Joined: Sep 21, 2011
Posts: 2407
posted
0
Sure, if you're certain that the HTML is formed that way, and will not change, then that's a possibility.
If you want to parse HTML in your Java code, then what you need (obvious as it may sound) is an HTML parser written in Java. So your Google keywords are java html parser... yup, I just checked, that gives you plenty of useful links.
Gary Sheldon
Ranch Hand
Joined: Nov 21, 2011
Posts: 44
posted
0
I've been trying to find a useful jsp HTML parser but not had any success, some libraries but no clear instructions as how to implement.
I don't think the HTML will change anytime soon but would appreciate any links that demonstate how to do what I've suggested.
There's several perfectly good HTML parsers out there. Can you point one of them where you consider the "implementation instructions" to be inadequate?
Gary Sheldon
Ranch Hand
Joined: Nov 21, 2011
Posts: 44
posted
0
Ok, ive looked at Jsoup but struggling with the implementation.
I have uploaded jsoup-1.6.2.jar to WEB-INF/lib and have the following code at the top of my jsp page: