PHP and XML

I l @ ve RuBoard

Now that you've seen what PHP and XML are each about individually, you're probably wondering how the two of them fit together.

The overall vision of XML and its ancillary technologies is very clear ”mark up data in XML, format it with XSL, link it together with XLink, and use it in a myriad of different ways. In reality, though, this overarching vision hits an obstacle at the first stage itself ”most browsers don't come with either an XML parser or an XSL processor. The latest versions of Internet Explorer and Netscape Communicator do support XML, but older versions don't. And this begs an obvious question: given that these browsers do not support XML (or support it in an incomplete manner), how do you, as a web developer, even begin to build the next generation of cutting-edge XML applications?

Well, there's a simple solution: insert an intermediary layer between the client and the server to handle the processing of XML-encoded data. This intermediary layer can handle XML parsing, XSLT transformation, and other related tasks , serving as a translator between the server (which has XML data to transmit) and the client (which only understands a specific language like HTML or Wireless Markup Language (WML)).

That's where PHP fits in. PHP serves as the meat in the sandwich, acting as the intermediary layer through which all XML processing is handled. Although PHP does not (yet) support the entire family of XML technologies, the latest version does include a very capable XML parser with both DOM and SAX extensions, and an XSL processor, through its Sablotron extension.

PHP also supports Web Distributed Data Exchange (WDDX), a rapidly emerging XML-based standard for data transmission over the web and can be coaxed into working with XML-RPC and SOAP to issue XML-based procedure calls over the Internet. Finally, because PHP has support for a wide variety of databases, it's possible to use the language to build an XML document from a database or populate a database by parsing an XML document.

Some of the applications that arise as a result of this combination are

  • Data processing. PHP's XML functions make it possible to parse XML data and carry out commands based on the type of data encountered . With some clever coding, this can be used to easily convert XML-encoded data into browser-compliant HTML output.You also can use PHP's XML functions to create a database from an XML document, or vice versa.

  • Data transformation. PHP's XSLT extension brings the full power of XSLT processing to the language, making it possible to apply XSLT stylesheets to XML data. With support for a wide range of XSLT processing instructions, transforming data from one format to another becomes very simple.

  • Platform-independent information exchange. PHP's WDDX functions make it possible to easily transfer information (including typed data like arrays) from one system to another using platform-neutral data structures. This capability is particularly useful for content publishers who need to disburse information to requesting clients on a periodic basis, yet have no control over the platform and operating environment of those clients ”for example, news syndication services or stock market tickers. Because WDDX structures are platform-neutral, the PHP/WDDX combination encourages interoperability by making it possible to exchange data between programming languages in a simple and elegant manner.

  • Remote process execution. Support for XML-RPC implies that PHP scripts can trigger processes on remote servers by sending them messages encoded in XML. This makes it possible to access different web services directly from your PHP script using standard client-server protocols and create new types of web applications based on these services. These processes/scripts might be written in other languages (such as Java, Python, Perl, and so on), again demonstrating how the XML/PHP combination can encourage greater interoperability between platforms and languages.

I l @ ve RuBoard


XML and PHP
XML and PHP
ISBN: 0735712271
EAN: 2147483647
Year: 2002
Pages: 84

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net