开发者

Serializing html and css, and storing in mysql

I am in the process of developing an html template generator. I would like to store the templates in a mysql database (or text files if that would be more efficient). I am looking for the best way to serialize the html and css, and then reproduce the original efficiently.

Javascript and php will be used to create/edit/and remove elements from both the browser and the database for later reproduction.

Elements can be added 开发者_如何转开发such as div, p, a, etc. and nesting should not be an issue. The main problem I am having is if a div is nested within a div and a paragraph element is nested within the second div at a later time, how would all of this be stored in a database? Elements will be deleted and new elements will be added in random order.

I hope this was somewhat clear. I am not really looking for code, but suggestions on how all of this would work together. Any help would be greatly appreciated. Thanks in advance


Store the entire thing as a blob in a single field in the database. Unless you're doing something quite novel, there's no reason the database layer needs to have an in-depth understanding of DOM structure.


I want to first point out that, what you need is a parser not a serialising method. You can simply store the template, then when you read it out, parse each individual element and then build the editing form. Sort of like xtgem does. No need to serialise. Unless you already parsed the data in an array.

If each user has his own template, then the chances of multiple reads is very low. Almost nill. Flat files will do very well in this siiuation. No need to sanitise and better performance. Do not forget file locking though.

If you are returning data in text input or textarea elements, no problem with xss. You don't need to sanitise output either.

I agree with @Rex. When I was developing a forum, I found that storing the original was better. It allowed for easy editing.

It would be best to separate the files and parse them separately. Keep presentation separate from markup. Parsers have never been my forte however. So I can't help in that aspect. You can take a look at pcltemplate from http://phpconcept.net to see how the parser works. Maybe give you ideas.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜