To put together html that you send to a browser you can easily just paste together a few strings, this is actually what I've been doing for a long time with only a few exceptions. But if we really want to do it the clean way we should use the Document Object Model, this way all our tags are closed for sure and we can easily attach something in the middle of an already existing piece. While in theory this sounds perfect, I've almost never seen any code using it. So when and why are you guys using or not using the DOM?
Using DOM to create HTML output has a big drawback -- a very difficult (if at all) template implementation, unless it's pure CSS. That's why most of the time you will see pre-made HTML documents used as templates.
But DOM does not limit you to HTML documents, you can use it to parse XML documents, or build them. However, SimpleXML is easier and more powerful to use, so you're better off with that most likely.
Where DOM comes really handy, though, is for building spider-like programs. Combined with HTML Tidy it can do wonders.
The only moments I use it is for generating feeds.
But I'm planning to rewrite my template-engine was thinking of using the DOM for that, although the benchmark-tests I wrote for my first attempts weren't very promissing.
That isn't surprising. DOM manipulations are pretty verbose.
The DOM is great for changing an existing document, but writing a whole one from scratch is going to be slow, and doesn't hold any real advantages that I can think of.
Bookmarks