ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

Best Approach to store and load a lot of text snippets into a web page


My project is a web-application that I'm writing using C# webforms.
I have a few hundred small text blocks - (actually prayers) that I want to load into the web page and arrange so the user can easily find what they want.

Now, my question is how to store them.
I could put them in XML or an access database or a sql database, or I can just type them all right into the web page.

The thing is that if I put them in a database, I can enclose everything in the proper divs that the webpage needs to display them with sortable jquery menus and accordians.  If I typed them into the webpage, it would be hard to know what is in the page, exactly, and I'd have to type all the divs.  So, I'm leaning toward a database or xml for storing the prayers with their titles, imprimaturs, and perhaps comments.

Should I use xml, sql or accdb for storing things?  Which would be faster to load and search?

I don't know a great answer to this, but one compromise option might be like this:

Use a javascript data table script, where you can provide your text data as json data embedded in the page itself.

The advantages of this are:

1. The text block data is clean data that you could use in a different way with any script or standalone application that can load json, and its not hardcoded as html text on a page, and it would be easy to convert the data to different formats later.
2. The data table script can let people do things like sort, search,etc.

Mouser,  so, I considered json, but I hate dealing with all those quotation marks.  XML, I decided was clumsy.  I ended up trying my hand at a sqlite.  I was reading that it has a performance superiority over json or xml, and I want to easily add more items.  Plus, I can use a type:text and store literal carriage returns.  In json or xml I'd have to always keep typing escape characters.

So, in C#, I just query the sqlite db into a datatable and then I can regex replace \r\n with <br/>.
And, as you said, I can store all the prayers in plain old text in the db and be able to use it for other applications, too, if I want.
Finally, I went with a .db because if I get up into having 500 prayers in the database, it will be much more manageable than a giant json file.

Thanks for your tips, though, even though I already decided what to do before you posted...   :D


[0] Message Index

Go to full version