Introduction to Server-Side XML

It sets the scene for server-side XML, and shows what you can do with it, by way of a parallel example done in ASP, PHP, and JSP (we have only included the first of the example sections here). The three chapters that follow this one in the book are case studies, which go into using XML with the three server-side languages mentioned above in much more detail.

This sample is taken from Chapter 8 "Introduction to Server-Side XML" of the glasshaus title "Practical XML for the Web".

Server Used for Examples

For the examples in this chapter, we used IIS 5.0 on Windows 2000 Professional. IIS comes with Windows 2000, and is an add-in component. The examples in this chapter will actually run with MSXML versions as old as MSXML 2.0, so if you have IE 5 or newer on your machine, you will be OK in this respect.

ASP.NET

You've probably heard of .NET  one of the latest Microsoft initiatives. Along with updates to much of its software and languages, we now find ASP.NET available to us. This extends the functionality of ASP to include all of the .NET Framework, including some expanded libraries for working with XML. However, this is rather a large area to explore, so we won't be covering it in any detail in this book.

PHP

PHP: Hypertext Preprocessor (PHP) is a server-side scripting language that can be embedded in HTML pages. It has been around for a few years now, but has undergone significant changes over that time. PHP borrows much of its syntax from Perl. When it was first created, it was intended to provide a more trimmed-down, easier-to-write, HTML-embeddable alternative to Perl, a task at which it seems to have succeeded. PHP is free, cross-platform, open source software; it integrates with all major web servers on all major operating systems.

Advantages

·          It's open source and freely available from http://www.php.net/.

·          It's cross-platform.

·          It has a very active user community.

·          It's seen as having a light footprint and not being processor-intensive.

Drawbacks

·          It's relatively difficult to expand the language to add non-standard functionality that not handled by its built-in functions.

·          PHP's extensibility is limited compared to say, Java, ASP, and COM (although new libraries pop up with every release)

·          The function syntax to connect to each different brand of database is slightly different. Compare this to Java, which has a generic JDBC interface to connect to databases or ASP, which has its ADO abstraction layer.

XML Support

PHP has 4 extensions for performing XML tasks. Perhaps the most widely used of these are the XML parser functions  these use the Expat library, a SAX-based parser. Although it can parse XML, it does not perform any validation of the document. It supports 3 character encodings, namely US-ASCII, ISO-8859-1 and UTF-8, but does not support UTF-16. As you already know, with a SAX parser you define event handlers for XML events: as the parser works through the XML document it will call these handlers as and when events occur. The Expat library can be found at http://www.jclark.com/xml/.

PHP can also do DOM parsing of the XML document, but at the moment this extension is considered experimental. The extension is being overhauled for PHP 4.3.0 and the behaviour of many of the functions may change, so when using this extension it is best to avoid any non-object-oriented function (a full list of deprecated functions is available with the documentation). The extension uses the Gnome XML library, which you can find at http://www.xmlsoft.org/.

The PHP extension that provides XSLT support currently supports the Sablotron library. This extension has recently been rewritten in order to provide support for other libraries like Xalan and libxslt. Sablotron can be found at http://www.gingerall.com/.

For our PHP examples here to work properly, you need to make sure you have the XSLT and XML DOM extensions installed. Don't worry, as they are included in the PHP package downloadable from http://www.php.net/do_download.php?download_ file=php-4.2.2-Win32.zip (see the InstallPHP.txt file in the code download for more instructions on installing this properly).

Finally, PHP also contains RPC support through the XMLRPC extension, although this is also considered experimental.


George Petrov

George PetrovGeorge Petrov is a renowned software writer and developer whose extensive skills brought numerous extensions, articles and knowledge to the DMXzone- the online community for professional Adobe Dreamweaver users. The most popular for its over high-quality Dreamweaver extensions and templates.

George is also the founder of Wappler.io - the most Advanced Web & App Builder

See All Postings From George Petrov >>

Comments

Be the first to write a comment

You must me logged in to write a comment.