Best way to store html in a database

barx

Well-Known Member
Licensed User
Longtime User
Morning all,

My aim is to store a section of html in a database field to be inserted as part of a html string into a webview. It will be a <table>.....</table>. Can't really do it in code as sometimes the table is required, sometimes not. And also the table can have different amount of cols and rows.

This data will not be updated by the app, just read.

Is it best to store this as a string, or a blob. Never used a blob before, so just want to make sure I'm making the right decision. I'm assuming a blob doesn't need quotes escaping etc?

Thanks
 

DouglasNYoung

Active Member
Licensed User
Longtime User
barx,
without knowing the complexity of the HTML it is very difficult to give a definitive answer. Assuming the contents of the table are populated from variables then you will need individual tags to wrap around the table contents.

I'm not sure if a database is necessary, but if you so choose then string format would simple to implement. Since you are going to have to pull the appropriate tags out the database at the appropriate time by some program logic then it might just be simpler to have the tags embedded in the program!

Cheers,
Douglas
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Thanks for this. I will try to explain without boggling you too much. Basically trying to create an app to be a user instruction manual for security systems. Using listviews so user can select make / model and the commands supported. Then when user selects a command another acivity will show the details of what that command does. These commands are already stored in db so I can easily expand the app to support more models. Some of the info is best shown in tabulated form. So I thought easiest way to show and style this would be a webview. Then in code I build a html string of the common parts and include and if statement to see if the 'table required' field for the command is true. If it is then simply concatinate the 'table 'data' field into the html string in the right place. Nothing fancy in table, all plain text. And every table will be formatted the same so not even a need for class or id tags. Could just style the <table> tag In a css file (there's a point, can you link a css file into a webview). So it will literally be '<table><tr><th>col header1</th>.......</tr><tr><td>some text</td>.......</tr></table>'

The reason to store in database like this is so it's easy to do different number of cols and rows without splitting csv etc

Thanks

Sent from my HTC Vision using Tapatalk
 
Upvote 0

DouglasNYoung

Active Member
Licensed User
Longtime User
In that case I'd probably store the html in a table with fields of
Make, Model, LineNo, html
and each line of html would have its own record in the table. While this would result in a bigger table it will be very easy to read and maintain. If you increment line numbers in 10s then there will be plenty of scope for inserting amendments!

Alternatively you could just hold Make, Model and Filename in the table and download all the html files complete to the user's device for direct loading to the webview. Its not hard with the HTTPUtils library to download the database as required and then check for any new Make/Models and download their html file.

Douglas
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Thank you both. Will have a play and see how it turns out ;)

Sent from my HTC Vision using Tapatalk
 
Upvote 0
Top