I’m working on an “advanced” version of an XHTML/HTML5 outputter class (with element-specific validation and error-reporting, structural hints, etc), that’s actually wildly different than what follows, but I’ve found myself coming back to this basic version a couple times (usually extending it for modularized page fragments), so thought I’d post it quickly. As usual, no documentation :)

Since writing this up, I’ve come across a couple similar classes online – the major differences being syntax (this one’s a little like JS, AS and C#), and that mine’s a little more flexible (you can use raw markup as a ‘child’, adding, removing, repositioning, etc); mine pretty-prints (tabs) by default; and I use the __toString magic method. That said, it’s very basic, without much in the way of validation or error-checking – partially by design, partially because I’m spending time on those kind of things with the fully-featured (and much larger) XHTML class.

usage…