How NPR's new website stores html markup separated from content in the database.
blog.programmableweb.com
blog.programmableweb.com
For example, they show the <em> tag being stored by position in the database separately from the content itself, seemingly unaware of the significance that <em> is a semantic tag. It means emphasis. If the iPod doesn't like <em> for emphasis, well then that's why it's a semantic tag. You can remove semantic tags or replace them with alternative markup or binary formats as needed because they have meaning designed for parsing and formatting.
It's all well and good to hate on XML for inappropriate uses. But, critical point here, documents are what XML is for! And there is a shocking wealth of libraries in just about every language available today that will handle document markup just fine.
It seems to me to be a quintessential reinvention of the wheel, and the XML hating has just gone on too far at this point.
For example, if you store all documents in a restricted version of HTML, then you can generate a text-only version by replacing all <em> and </em> with star, etc. This is much cheaper than actually parsing XML (no need to build up a data structure representation of the document, just assume it is mostly right already and apply textual transformations).
Then, once you have the plaintext version, cache it. Journalism sites are going to have an absurd number of reads to writes. (One guy writes the article, one guy edits it, 50,000 people see it within a minute of it being posted.) Caching is cheap and easy. Caching is robust against the article changing, too -- you purge the cache (or potentially just let it expire) and bam your new article is mostly right, whereas tracking the offset of <em>s seems to intuitively have a lot of possible failure modes to me. (For example, the first time one of your reporters tries to add a bit of local color with Japanese text in an article, I'll bet dollars to donuts that every tag after the Japanese breaks and the surrounding content gets corrupted.)
As long as you tightly control writes to the database, I don't see the problem. And, you don't have the overhead of parsing on every read. For an environment where reads will be a few orders of magnitude greater than writes, it does make some sense.
Considering how quickly CPU and disk performance change, this type of tightrope-balanced optimization seems crazy. Or maybe they're way smarter than me.
I'm especially doubtful of it, because the article doesn't explain the problem with the obvious approach you suggested.
I feel bad to be so negative toward an idea I haven't fully explored, but I get the impression that the author of this article is trying hard to justify a bad approach rather than fixing the code.
As an example madair in an earlier comment notes that em is intended to be a semantic tag. But do the semantics of this particular tag ever mean anything outside of "show this text as emphasized"?
I am wondering if whatever semantic markup we do is still all about presentation, and takes a fairly arbitrary abstraction of what the text is to mean.
The semantic tags are the means, but output presentation is still the end, and there's certainly no reason to expect that all devices can take the original semantic markup and use CSS or some other mechanism to present it. And because of the semantic meaning we can make the em disappear with confidence.