developerWorks : XML : Features / Library - Papers
Home
Products
Consulting
Industries
News
About IBM
IBM : developerWorks : XML : Library - papers
PHP developers: Fill your XML toolbox Essential tools and libraries for using XML with PHP Craig Knudsen Web Engineer, ePresence, Inc. June 2000 The PHP scripting language's XML support has a few gaps, but you can fill them with Java objects in a pinch. In this article, find out what XML tools are available now for PHP developers looking to craft XML projects, and find out how to access Java objects until the PHP tool set matures. PHP often has been one of the first languages to implement new technologies. In the case of XML, PHP first added support back in version 3.06, which was released in December 1998. Building expat into PHP 4 PHP 4.0, which was recently released, uses James Clark's popular C-based expat parser, which is also the XML parser used by the Mozilla browser. PHP 4 includes expat in the distribution, so enabling XML support is as simple as using the --enable-xml switch as part of the configuration step when building PHP as seen below:
Contents:
expat in PHP 4 Working with PHP 3 Looking to the future Using Java objects Choosing your tools Resources About the author
./configure --enable-xml -with-apache=../apache_1.3.12
Of course, you'd probably want to set other options as well when you configure. Because PHP 4 uses the expat parser, limitations of that parser apply to PHP. For example, because expat is not a validating parser, PHP's XML module cannot do any validation against a DTD. Working with PHP 3 If you're using PHP 3 and Apache 1.3.7 or later, you can use Apache's expat library. (The XML section of the PHP Manual has detailed instructions on setting up XML support in PHP 3. See Resources.) Looking to the future The PHP team is currently working on adding support for a DOM extension using the GNOME Project's libxml (which uses the W3C's XML parser), which can turn any XML file into a DOM object tree and manipulate that tree. Experimental code is already in PHP 4, but it is scarce (as of PHP 4 RC1). Using Java objects in a pinch PHP does not have the wide variety of XML tools that are now available for Java developers and Perl developers. However, PHP 4 includes support for accessing Java objects, putting the wide variety of Java language XML tools at the disposal of PHP developers. You don't need to know how to write Java code to take advantage of this method, although you'll find it easier if you have some familiarity with Java language calling conventions (such as method overloading). PHP's Java language support is new and documentation is not yet available, but expect this to improve. For now, developers interested in accessing Java objects need to examine two examples provided within the PHP distribution (found in the same directory as the Java extension.) Some problems exist with the interaction between PHP and the Java language. The Java language's method of overloading is not 100% supported by PHP's Java extension because the PHP language does not support method overloading. The setup process differs slightly for each implementation of Java objects. See the README file in the ext/java directory of your PHP distribution. (Only Red Hat 6.1 and Windows NT 4.0 instructions are included; it is not clear when other operating systems will be supported.) When building on a Red Hat Linux 6.1 system with Blackdown’s JDK 1.2.2 RC 4, I did encounter a problem with the PHP configure script that would not allow me to use just the --with-java option. Instead, I had to specify the location of the JDK using --with-java=/opt/jdk1.2.2 instead. be sure to copy or move the php_java.jar file and the libphp_java.so file into permanent locations (they are not installed as part of the "make install" process), so they can be referenced in your php.ini configuration file (as seen in the ext/java README file.) The following example demonstrates how to call Java objects from within PHP.
http://www-4.ibm.com/software/developer/library/php-xml-toolkit.html (1 of 3) [6/23/2000 9:52:56 AM]
Search
developerWorks : XML : Features / Library - Papers Listing 1. Calling Java objects from within PHP
$system = new Java ( "java.lang.System" ); print "Java version: " . $system->getProperty ( "java.version" ) . "
\n"; print "Java vendor: " . $system->getProperty ( "java.vendor" ). "
\n"; print "OS: " . $system->getProperty ( "os.name" ) . " " . $system->getProperty ( "os.version" ) . " on " . $system->getProperty ( "os.arch" ) . "
\n"; Processing stylesheets
Developers who want to use XSL to translate XML documents into HTML will find it difficult to do so in PHP alone. Because the Java language has many XSLT tools, using the new Java extension will greatly simplify this task. Choosing your tools The following tools summary lists the XML tools that you can now use with PHP. If you can't find what you're looking for in the table, check out the XML tool summary for Java developers (see Resources) and get moving on calling those Java objects from within your PHP scripts. Tools summary Parsers and object models: Generic XML parser
PHP class that uses PHP's XML API to parse arbitrary XML input.
PHP RAX
A PHP port of the XML::RAX Perl module.
XMLtree
Another PHP class used to help parse XML input.
XSLT processors: PHP Sablot extension
A PHP extension that provides an interface to Sablotron XSLT library.
Protocols: XML-RPC PHP
Remote procedure calling (RPC) using HTTP as the transport and XML as the encoding. This class implements XML-RPC for PHP.
WDDX
Protocol for the exchange of data between different languages such as Perl, Java, ColdFusion, and PHP. This module converts PHP variables to and from WDDX packets. You must install the WDDX SDK to enable WDDX support in PHP.
Horde Projects's Jonah tool
Protocol for retrieving and parsing RDF/RSS files. RSS (Rich Site Summary) is most often used to represent news items, commonly called channels.
Resources ●
Read the PHP Manual's section on XML for installation tips and examples.
●
Learn how to use XML-RPC to implement remote procedure calls with PHP in Backends Sharing Data.
●
Keep up with the latest XML news and views at XML.com.
●
Add your name to the PHP-XML mailing list hosted by The O'Reilly Network.
●
Subscribe to the PHP XML-RPC interest mailing list to stay current on all XMP-RPC PHP activities.
●
Find XML tools for Java developers in "Java developers: Fill your XML toolbox" on developerWorks.
●
Join the exchange in the new (June 2000) PHP-XML newsgroup, or download the contents.
About the author Craig Knudsen has been developing Web applications since 1994 using a variety of tools and languages. Craig currently telecommutes from Fairfax, Virginia, as a Web Engineer for ePresence, Inc., of Red Bank, New Jersey. You can reach him at [email protected].
http://www-4.ibm.com/software/developer/library/php-xml-toolkit.html (2 of 3) [6/23/2000 9:52:56 AM]
developerWorks : XML : Features / Library - Papers What do you think of this article? Killer!
Good stuff
So-so; not bad
Needs work
Comments?
Submit feedback Privacy
Legal
Contact
http://www-4.ibm.com/software/developer/library/php-xml-toolkit.html (3 of 3) [6/23/2000 9:52:56 AM]
Lame!