Chapter 2. PHP and the Simple API for XML (SAX)
"I am not young enough to know everything."Oscar Wilde
If You're new to XML, something bad will happen to you right after you finish converting your little black book into XML-compliant format. You'll lean back in your swivel chair, sip a glass of wine, ponder the remnants of your shattered weekend, and ask yourself: "Now what?"It's a question every XML newbie asks at least once, and it's not hard to understand why. When you're first learning XML, it's easy to get lost in the intricacies of namespaces and entities, and to find satisfaction in the successful creation of valid XML documents and DTDs. As you gain experience, though, you'll find yourself wondering if there shouldn't be more to this than just tags and theory.Well, you're right to wonder, and you're right in thinking that there's more here than meets the eye. Marking up data in XML is only the first step; the true value of the language becomes visible only when you try to do something useful with all that marked-up data. Because XML makes it possible for applications to easily recognize and operate on disparate pieces of data, it allows developers to do some complex things in very simple wayswhich, when you get down to it, is what good programming is all about.In this chapter, I will be attempting to answer that "Now what?" question by describing one of XML's simplestyet most potentapplications: parsing and formatting marked-up documents for greater readability and better presentation. My weapon of choice here will be the Simple API for XML (SAX), implemented via PHP. So keep reading!