Page 343 - Open Soource Technologies 304.indd
P. 343
Unit 13: Extensible Markup Language
xslt_free($processor); Notes
echo “<pre>$result</pre>”;
?>
The following given example contains the same transformation as Example but uses XML and
XSL values from an array instead of going directly to files. In this example there’s not much
point in using this technique, as we get the array values from files. But if the XML document
or XSL transformation is dynamically generated, fetched from a database, or downloaded over
a network connection, it is more convenient to process from a string than from a file.
XSL transformation from variables
<?php $xml = join(‘’, file(‘news.xml’));
$xsl = join(‘’, file(‘news.xsl’));
$arguments = array(‘/_xml’ => $xml, ‘/_xsl’ => $xsl);
$processor = xslt_create( );
$result = xslt_process($processor, ‘arg:/_xml’, ‘arg:/_xsl’, NULL, $arguments);
if(!$result) exho xlst_error($processor);
xslt_free($processor);
echo “<pre>$result</pre>”;
?>
13.6 Web Services
Historically, every time there’s been a need for two systems to communicate, a new protocol has
been created (for example, SMTP for sending mail, POP3 for receiving mail, and the numerous
protocols that database clients and servers use). The idea of web services is to remove the need
to create new protocols by providing a standardized mechanism for remote procedure calls,
based on XML and HTTP.
Web services make it easy to integrate heterogeneous systems. Say you are writing a web interface
to a library system that already exists. It has a complex system of database tables, and lots of
business logic embedded in the program code that manipulates those tables. And it is written
in C++. You could reimplement the business logic in PHP, writing a lot of code to manipulate
tables in the correct way, or you could write a little code in C++ to expose the library operations
XML-RPC and SOAP are two of the standard protocols used to create web services. XML-RPC
is the older (and simpler) of the two, while SOAP is newer and more complex. Microsoft’s
.NET initiative is based around SOAP, while many of the popular web journal packages, such
as Frontier and blogger, offer XML-RPC interfaces.
PHP provides access to both SOAP and XML-RPC through the xmlrpc extension, which is based
on the xmlrpc-epi project. The xmlrpc extension is not compiled in by default, so you will need
to add with-xmlrpc to your configure line.
13.6.1 Servers
The following given example shows a very basic XML-RPC server that exposes only one function
(which XML-RPC calls a “method”). That function, multiply ( ), multiplies two numbers and
returns the result. It is not a very exciting example, but it shows the basic structure of an XML-
RPC server.
LOVELY PROFESSIONAL UNIVERSITY 337