Reputation: 31
Suppose I've below html string.Each div consists of User name ,Time, date and comment.I need to save this content in db but before that i need to modify date and time of last div with new date and time.
<div class=\"customclass recordwidget comments-section\" style=\"margin-bottom:8px; background-color:#f8f8f8; border-bottom:1px solid #f01928;border-top:1px solid #f01928; padding:8px; line-height:1.1;\"><div class=\"headingcontent\"><b style=\"font-size:15px;\">Rob</b> <b>2/9/2018</b> 8:43:5 </div> <div class=\"recordwidget-content\"><p>Comments to modified date</p>\n </div> </div><div class=\"customclass recordwidget comments-section\" style=\"margin-bottom:8px; background-color:#f8f8f8; border-bottom:1px solid #f01928;border-top:1px solid #f01928; padding:8px; line-height:1.1;\"><div class=\"headingcontent\"><b style=\"font-size:15px;\"> om</b> <b>4/25/2018</b> 8:8:32 </div> <div class=\"recordwidget-content\"><p>Hello World</p>\n </div> </div><div class=\"customclass recordwidget comments-section\" style=\"margin-bottom:8px; background-color:#f8f8f8; border-bottom:1px solid #f01928;border-top:1px solid #f01928; padding:8px; line-height:1.1;\"><div class=\"headingcontent\"><b style=\"font-size:15px;\"> Perry</b> <b>4/26/2018</b> 4:1:58 </div> <div class=\"recordwidget-content\"><p> bbb </p>\n </div> </div>
If html contain only one div then that is last div need to modify.Please let me know how can achieve this in Java.
Upvotes: 1
Views: 177
Reputation: 483
I assume your main objective is to store the data into database and make this dynamic for various purposes / elements.
Step 1) First grab the DIV and stored it to a variable
Step 2) Transform the DIV to XML / JSON (incl of data type) based on a schema. Don't forget to handle failure scenario
Step 3) Apply your business logic or any other modifications
Step 4) Use XML path or Json Path to get the data you want to store and iterate the same
All the above could be achieved by java code
Upvotes: 1