Chapter 23. Expresso and XML

Table of Contents

Introduction
XML Configuration Files
XML Data Import/Export
XML Output from Controllers
XSL Stylesheets
Conclusion
Contributors

Note

If you find this EDG documentation helpful please consider DONATING! to keep the doc alive and current.

 Maintainer:David Lloyd

Expresso contains a number of XML capabilities that can be used in building your application. This chapter explores these briefly, and how then can be applied. Expresso XML provides XML aware components for use with Expresso, including XML import and export of DB Objects, XSLT transformations for easy UI reconfiguration, and parsing of XML data for configuration and setup values. In order to keep the Expresso Framework project modular, we have separated Expresso XML as it's own project. Expresso XML includes the two required libraries (namely Xerces & Xalan) that Expresso will use only if XML handling is required.

Introduction

Expresso XML project provides basic facilities for importing and exporting DBObjects to XML format streams and/or files. In addition, a Transaction object has been developed that allows multiple imports and exports via servlets between servers, creating the basis for an XML-based replication. Expresso XML includes and incorporates a copy of the Apache Xerces XML parser and the Apache Xalan XSLT transformation tool.

XML Configuration Files

The configuration files that specify all of the options for Expresso at system startup are in XML format, and these files can be used to specify additional custom properties for your own application. See the "custom-property" element description in the DTD for expresso-config.xml for details. (This DTD can be found in the WEB-INF/classes/com/jcorporate/expresso/core directory.

XML Data Import/Export

A controller object called XMLController can import data into any DBObject from an XML format, and export data from the DBObject into an XML format file. This controller is accessed from the "Operations" page in Expresso.

XML Output from Controllers

All Controller objects can produce their inputs, outputs and transitions in XML format. This can be used when debugging an application, to examine the elements produced by a particular controller. This XML can also be passed through a specified XSL stylesheet, to produce HTML, WML, PDF, or other XML, as required. This ability is provided by the XMLViewHandler servlet.

Any Controller can be invoked via it's URL with the "style=xml" option. "style=xml" in conjunction with "xsl=none" will produce the XML output directly to the browser. Any other "xsl=..." option will use the specified stylesheet for transformation. If no XSL is defined, the XSL to be used will be determined by the Controller/XSL mappings (defined from the "Setup" page) in the current context.

XSL Stylesheets

The use of XSL stylesheets with Controller outputs can be invoked according to a URL parameter, as described above. Furthermore, the configuration file can specify an xsl transformation. That is, instead of specifying a forward for a JSP, a forward can be specified for a .xsl file. For example, considered the action mapping below, from an entry in a fictitious configuration file "myProject-config.xml":

<action path="/MyController" type="com.jcorporate.myproject.controller.MyController" name="default" scope="request" validate="false"> <!-- This method is rendered by a JSP --> <forward name="someMethod" path="/myProject/jsp/register/status.jsp"/> <!-- you can use XSLT transforms here too. any path which ends with .xsl or .xslt will be handled appropriately. --> <forward name="someOtherMethod" path="/myProject/xsl/blah.xsl"/>; </action>
In this configuration file, the .xsl forward will be interpreted by Expresso to mean that the forward will be remapped to "xml", which by default is /servlet/XMLViewHandler, and the xsl information is automatically added to the request with a parameter. Note that the mime type for XSL transformations is assumed to be HTML. If you wish to transform from XML to XML, add a parameter to the request as follows:
class MyController ... protected void runSomeOtherMethodState(ControllerRequest request, ControllerResponse response) throws ControllerException { ... // set mimetype of result, since xsl is usually translated to html, but // in this case we will be outputting xml request.setParameter("mime", "text/xml"); }
Expresso incorporates and includes the Apache Xalan XSL processor, and this processor can be accessed directly to perform custom XSL transformations as required. See the source code for the XMLViewHandler object (in the com.jcorporate.expresso.core.servlet.viewhandler package) for an example of how to access Xalan programmatically.

Conclusion

The direction of this project is to adopt a standard XML DTD for representation of Database Objects and making the XML parser 'pluggable' as well as providing XSLT transformation capability (ala Cocoon). Much more is also possible with the XSLT transformations - one goal here is to make a version of the DBMaint servlet with a completely customizable UI via XSL stylesheets.

Contributors

The following persons have contributed their time to this chapter:

Note

Was this EDG documentation helpful? Do you wish to express your appreciation for the time expended over years developing the EDG doc? We now accept and appreciate monetary donations. Your support will keep the EDG doc alive and current. Please click the Donate button and enter ANY amount you think the EDG doc is worth. In appreciation of a $35+ donation, we'll give you a subscription service by emailing you notifications of doc updates; and donations $75+ will also receive an Expresso T-shirt. All online donation forms are SSL secured and payment can be made via Credit Card or your Paypal account. Thank you in advance.

Copyright © 2001-2004 Jcorporate Ltd. All rights reserved.