XML Application Objects (logo)
100% XML web applications
SourceForge.net Logo
This page was last updated Wednesday 24 September 2003

Project Aims

Knowing the aims and objectives of XAO should help you understand how to use the code because you will understand the intent. This page shows the aims of the project. The concrete objectives are found in the project task lists and road map.

If you are a PHP developer, you might be thinking "There has to be an easier way to build XML/XSLT applications in PHP". Well, you'd be right, there is, and XAO is here to make that happen. XAO is one of those solutions which has come about as a result of an effort to remove the tedium associated with programming to the various APIs that PHP offers for XML functionality.

Aims of the XAO project

Simplicity

A web developer should be able to hit the ground running with XAO. The library is designed to present a simple interface to high-level functionality in XML and XSLT.

Standards based development:

Hopefully the simplicity offered by XAO will encourage more developers to build standards based applications. For instance, not using proprietary templating systems - forcing end users to learn a new templating language every time they want to re-skin a new PHP app they downloaded. They can use and re-use XSLT templates which are a W3C standard.

Flexibility

Since XAO is simply a library, the web developer can use whatever architecture they feel is appropriate for their projects. XAO provides the option of using it in framework mode, and even then, applying a model-view-controller pattern is optional.

Scalable complexity

While you can start off simple with XAO, as the needs of an application become more complex, you can start taking advantage of the more powerful aspects of the API. For instance, you can define call-back functions in situations where enhanced processing is required. You can take advantage of the OO design of the library and use inheritance to extend/customise functionality. Most of the XAO objects where designed to be extended.

A short illustration of how simplicity is achieved

Before we look at an example of using XAO code, here is an example of a simple XML/XSLT script written in PHP and not using XAO...


<?php
$objDomDoc 
domxml_new_doc("1.0");
$elRoot $objDomDoc->create_element("root");
$ndRoot $objDomDoc->append_child($elRoot);
$elGreeting $objDomDoc->create_element("greeting");
$ndGreeting $ndRoot->append_child($elGreeting);
$ndGreeting->set_content("hello world");

$arrArgs = array( 
    
'/_xml' => $objDomDoc->dump_mem(), 
    
'/_xsl' => implode("",file("skins/template.xsl")) 
); 

$procXSLT xslt_create();
xslt_set_base($procXSLT,realpath("skins"));
xslt_set_encoding ($procXSLT"ISO-8859-1");
xslt_set_error_handler($procXSLT,"xslt_trap_error");
$resHTML xslt_process($procXSLT'arg:/_xml''/_xsl'NULL$arrArgs);

xslt_free($procXSLT);

echo 
$procXSLT;

function 
xslt_trap_error($parser$errorno$level$fields) {
    echo 
"<h1>darn it!</h1>";
    if(
is_array($fields)) {
        foreach(
$fields as $label => $item) {
            echo 
"<p><strong>".$label.":</strong> ".$item."</p>";
        }
    }
}
?>

 

This is what the same code would look like in XAO...

<?php
include_once "XAO_AppDoc.php";          // import an XAO class
$strRootEl "root";                    // used to pass by reference
$objAppDoc = new AppDoc($strRootEl);    // instantiate an XAO class
$objAppDoc->ndSetStylePi("skins/template.xsl"); // set the stylsheet
$objAppDoc->ndAppendToRoot("greeting","Hello World"); // test data
$objAppDoc->Transform();                // execute the XSLT processor
$objAppDoc->Send();                     // send the payload.
?>

 

Notice that not only are there less lines of code, but it is also object oriented. As the name suggests, XAO is a class repository for people wanting to build object oriented applications. XAO helps to make it easier to tame the proceduralness of the PHP XML API to your object oriented design.

Using the XAO library in the fashion shown above turns each PHP page into the equivalent of the main(){...} method of your more traditional OO languages such as Java or C++. From this point of view, there is nothing stopping you from finally creating 100% object oriented XML applications in PHP.

In case you're wondering about the example, you can still access the full standard range of dom methods without choosing to use the XAO shortcuts. Instead of doing...

<?php
$objAppDoc
->ndAppendToRoot("greeting","Hello World");
?>

 

You could have done...

<?php
$ndGreetz 
$objAppDoc->objDoc->create_element("greeting");
$ndGreetz $objAppDoc->objDoc->append_child($ndGreetz);
$ndGreetz->set_content("Hello World");
?>

 

The choice is yours.

XAO is all about speeding up the process, it's not about dictating how you should do things. If you see a need for a shortcut that XAO doesn't support you simply inherit the XAO object and add the member function to your own class. Most of the XAO classes are designed primarily to be extended by you.

In tackling the original example, one could write some functions to act as shortcuts but you'll probably end up being in danger of repeating much of the work put into XAO. Why would every PHP developer want to write his/her own library of functions/objects in isolation if the functionality is generic [to XML in this case]? Wouldn't it be nice if you could leverage the work done by someone else? Using XAO can save you time and engergy spent on "the boring bits" so that you can spend more time writing code directly related to buisness outcomes rather than application infrastructure.

Its worth mentioning that XAO can work with other PHP libraries such as PEAR and phplib. XAO is a stand-alone library so that all the classes work together in harmony for a single purpose - to make developing 100% object oriented XML applications easy.

The XAO example shown above demonstrates XAO working in "framework mode". Note that it is possible to continue to use your own application framework and merely use XAO objects for convenient access to high-level XML functionality.

The XAO project will focus strongly on knowledge support by providing numerous tutorials (how-tos) as well as other documentation including awareness articles on this site. There are tutorials to illustrate simples tasks as well as suggestive tutorials on how one might approach large-scale application design using XAO as in framework mode. This documentation complements a full API reference which is generated by the JavaDoc style comments embedded in the library code itself. The user community is invited to contribute tutorials/articles for techniques that they may have developed independantly.

 

This website is copytight Terence Kearns 2003
The XML Application Objects library is copyright Terence Kearns 2003 and made freely available to the public via the Lesser General Public Licence (LGPL).
The hosting of this project is generously provided by sourceforge.net