05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

not much point in using this technique, as we get the array values from files. But if<br />

the XML document or XSL transformation is dynamically generated, fetched from a<br />

database, or downloaded over a network connection, it’s more convenient to process<br />

from a string than from a file.<br />

Example 11-14. XSL transformation from variables<br />

$xml, '/_xsl' => $xsl);<br />

$processor = xslt_create( );<br />

$result = xslt_process($processor, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments);<br />

if(!$result) exho xlst_error($processor);<br />

xslt_free($processor);<br />

echo "$result";<br />

?><br />

Although it doesn’t specifically discuss <strong>PHP</strong>, Doug Tidwell’s XSLT (O’Reilly) provides<br />

a detailed guide to the syntax of XSLT stylesheets.<br />

Web Services<br />

Historically, every time there’s been a need for two systems to communicate, a new<br />

protocol has been created (for example, SMTP for sending mail, POP3 for receiving<br />

mail, and the numerous protocols that database clients and servers use). The idea of<br />

web services is to remove the need to create new protocols by providing a standardized<br />

mechanism for remote procedure calls, based on XML and HTTP.<br />

Web services make it easy to integrate heterogeneous systems. Say you’re writing a<br />

web interface to a library system that already exists. It has a complex system of database<br />

tables, and lots of business logic embedded in the program code that manipulates<br />

those tables. And it’s written in C++. You could reimplement the business logic<br />

in <strong>PHP</strong>, writing a lot of code to manipulate tables in the correct way, or you could<br />

write a little code in C++ to expose the library operations (e.g., check out a book to<br />

this user, see when this book is due back, see what the overdue fines are for this user)<br />

as a web service. Now your <strong>PHP</strong> code simply has to handle the web frontend; it can<br />

use the library service to do all the heavy lifting.<br />

XML-RPC and SOAP are two of the standard protocols used to create web services.<br />

XML-RPC is the older (and simpler) of the two, while SOAP is newer and more complex.<br />

Microsoft’s .NETinitiative is based around SOAP, while many of the popular<br />

web journal packages, such as Frontier and blogger, offer XML-RPC interfaces.<br />

<strong>PHP</strong> provides access to both SOAP and XML-RPC through the xmlrpc extension,<br />

which is based on the xmlrpc-epi project (see http://xmlrpc-epi.sourceforge.net for<br />

280 | Chapter 11: XML<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!