| XML and PHP — for wannabe
Web architects
Prashant L Rao
 |
XML and PHP
Author: Vikram Vaswani
Publisher: Pearson Education
Pages: 358 |
If you don’t know XML from HTML (or SGML
for that matter) and think that PHP is something to do with chemistry, then
this book is most definitely not for you. On the other hand, if you know your
XML and have dabbled in PHP and want to start building websites that actually
do something useful—this book is right up your alley.
Vikram Vaswani’s style of writing is smooth
and easy and the book is peppered with code samples that you can play around
with and incorporate into your projects. Every chapter starts off with an appropriate
quote. The book kicks off with a short introduction to XML and PHP and how the
twain meet. From there you move on to SAX (Simple API for XML) and basic but
essential stuff such as event and input handling and that all-important bit—error
handling. From there the author moves on to PHP and DOM (Document Object Model).
This chapter teaches you how to traverse a DOM tree using PHP’s tools for parsing
DOM. This chapter ends with a short comparison of the relative merits of DOM
and SAX—two roads to the same destination.
So far, the book deals with the nitty-gritty
of capturing data, manipulation and output. Chapter Four takes a step forward
to show you how XSLT (Extensible Stylesheet Language Transformations) can be
used to create and format documents from an XML source. Once again, if you don’t
know your basic XSLT, you’re not going to get very far here. The book assumes
that you already know the basics. From there, Vaswani moves on WDDX (Web Distributed
Data eXchange), technology that lets you implement applications such as news
syndication, banner ad rotation, e-commerce applications and software update
services. After WDDX come XML-RPC (Remote Procedure Calls) and SOAP (Simple
Object Access Protocol). The latter includes ideas from both WDDX and XML-RPC.
This chapter covers the relative merits of these technologies and tells you
how to use them effectively.
The author then moves onto the crucial
topic of using databases with XML and PHP. He starts off by comparing XML and
databases, pointing out that XML isn’t a panacea for all tasks—there are things
that databases are better suited for, such as storing structured or volatile
data where they offer a much higher level of performance. On the other hand,
XML data, being plain ASCII text, is portable across platforms. The chapter
shows you how to connect to a MySQL database using PHP to convert the data into
XML and also teaches you how you can do the converse—import XML data into a
database.
In the final stretch, the author lists
a few alternatives to PHP’s native functions for everything from DOM to XML-RPC
and SOAP. The reasons for using these are that many of PHP’s built-in extensions
are experimental and in some cases using an external class is a viable option.
Vaswani winds up with case studies that tell you what happens when PHP rubber
hits the road. Here a couple of open-source software projects that address real
problems using PHP are profiled—Metabase and patTemplate.
You’ll need PHP 4.1 to run the examples
detailed in this book. The appendices give you the low-down on recompiling PHP
to add XML support, more than you probably want to know about open-source licenses
and a short glossary defining key terms used in the book.
The book’s companion website (www.xmlphp.com)
has zip files containing the code snippets listed in the book and links to additional
resources. There’s also a discussion forum on all the key topics covered here.
|