A Few Examples

Now that you know the theory, let’s see how it works in some real-life examples. The following sections illustrate how PHP’s SAX parser can be used to “do something useful” with XML data.

Formatting an XML Invoice for Display in a Web Browser

Consider the XML document in Listing 2.21, which contains an invoice for material delivered by Sammy’s Sports Store.

Listing 2.21. XML Invoice (invoice.xml)
 <?xml version="1.0"?> <!DOCTYPE invoice [ <!ENTITY message "Thank you for your purchases!"> <!ENTITY terms SYSTEM "terms.xml"> ]> <invoice> <customer> <name>Joe Wannabe</name> <address> <line>23, Great Bridge Road</line> <line>Bombay, MH</line> <line>India</line> </address> </customer> <date>2001-09-15</date> <reference>75-848478-98</reference> ...

Get XML and PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.