Custom XML templating with PHP
4th July 2003
Dynamic XML conversion using the SAX parser and a stack is the best new article I’ve seen on PHPBuilder in a very long time. It introduces several interesting ideas. The first is something I’ve been thinking about for a while now: using PHP’s output buffering to implement a kind of templating system so that all of the scripts in a system just have to generate an intermediate content type, then the output buffering function adds on the HTML framework and finalises the page. The second idea is ingenious: invent XML elements to represent specific behaviours, then handle them with a SAX before the page is displayed. Here’s some example code from the article:
<doc title="Pizza menu" bgcolor="lightblue"> <bigheadline> Pizza Palace - Our Menu for <dayofweek /> </bigheadline> <br /><br /> <b>Buon appetito!!!</b> <br /><br /> <nicebox bordercolor="green"> <product id="0" /><br /> <product id="1" /><br /> <product id="2" /><br /> <product id="3" /><br /> <product id="4" /><br /> </nicebox> </doc>
The tutorial describes a full implementation to make use of the custom tags demonstrated above. It’s advocating a full CMS where pages are described using a custom XML format, but the idea could be used in a whole load of different ways. I touched on this approach with my Form Validation prototype but this really shows how much further the concept can be taken. Best of all, the performance hit should be pretty minimal due to the absurd speed of PHP’s XML functions.
More recent articles
- Slop is the new name for unwanted AI-generated content - 8th May 2024
- Weeknotes: more datasette-secrets, plus a mystery video project - 7th May 2024
- Weeknotes: Llama 3, AI for Data Journalism, llm-evals and datasette-secrets - 23rd April 2024
- Options for accessing Llama 3 from the terminal using LLM - 22nd April 2024
- AI for Data Journalism: demonstrating what we can do with this stuff right now - 17th April 2024
- Three major LLM releases in 24 hours (plus weeknotes) - 10th April 2024
- Building files-to-prompt entirely using Claude 3 Opus - 8th April 2024
- Running OCR against PDFs and images directly in your browser - 30th March 2024
- llm cmd undo last git commit - a new plugin for LLM - 26th March 2024
- Building and testing C extensions for SQLite with ChatGPT Code Interpreter - 23rd March 2024