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 Apache 1.3.26 and PHP 4.2.2 on
Windows 2000 Professional.
JSP
JavaServer Pages (JSP)are
written in Java, which (unlike VBScript and PHP) is an object-oriented programming
language that can be used to build enterprise-strength applications. Java
is arguably the most powerful platform for server-side web development today.
Portability, multithreading, extensive class libraries, object-oriented code,
strong safety features, robust security measures, elegance, and extensibility
are just a few of Java's advantages.
Java was designed to be platform-independent and very portable. Therefore,
a web application developed in Java can be packaged as a WAR (web application
archive) file and installed on any Java-enabled application server, on any
platform.
The disadvantage is that Java is not very easy to learn. If you just need
to get a more simple site up and working quickly, and are not serious about
learning an object-oriented language, a simpler language like PHP might be
a better choice. By using JavaBeans and tag libraries, however, web designers
can quickly learn to create JSPs that retrieve data from a database, process
XML, and carry out other powerful functions, without having to know anything
about the underlying technology. You don't need to be a sophisticated Java
programmer to utilize the power of JSP.
JSP files can also be a little slower than ASP or PHP because of the way
they work. The first time JSPs are called, they are converted into servlets
(special Java classes that produce outputs for sending over HTTP), which are
stored by the JSP engine. After this, requests for the JSP files are served
from the converted servlet (JSP engines also double as servlet engines). The
most readily available JSP engine is Tomcat, which also serves static content
at a slower rate. If you want a fast web site, get a dedicated web server
such as Apache or IIS to serve the static content, while Tomcat (or another
engine) serves the JSP content.
Advantages
·
It's free. You can download the Tomcat application server from
the Jakarta web site, and start coding in minutes (assuming you've got Java
installed, which is also free).
·
It's cross-platform.
·
It has a very active user community.
·
It's extremely powerful and scalable.
Drawbacks
·
A steep learning curve.
·
Third-party hosting isn't common, and can cost extra for installation.
XML Support
There is enormous XML support in Java. There are loads of parsers and XSLT
and XPath processors available, and most of them are open source. To name
them all would be pointless, but the following is a short overview of some
of the products available (the list includes the most popular products in
each category).
XML Parsers
·
Xerces: Xerces is a high-performance,
fully compliant XML parser from the Apache XML Project. It is a fully conforming
XML Schema processor. It is free, and available both in sourcecode and precompiled
binary (JAR file) form. For more information, visit http://xml.apache.org/xerces2-j/index.html.
·
XML4J: XML Parser for Java is a validating
XML parser and processor written in 100% pure Java a library for parsing
and generating XML documents, available as freeware from IBM. For more information,
visit http://www.alphaworks.ibm.com/tech/xml4j.
·
XP: XP is an XML 1.0 parser written in
Java, fully conforming, which detects all non well-formed documents. It is
currently not a validating XSLT processor, but it can parse all external entities:
external DTD subsets, external parameter entities, and external general entities.
For more information, visit http://www.jclark.com/xml/xp/.
·
MXP1: MXPl, or Maximum Perf. Minimum Size
XML Parser, is a Java-based, non-validating pull
parser that implements the Common Application Programming Interface (API)
for XML Pull Parsing (http://www.xmlpull.org)
specification. MXP1 was designed for minimal footprint (less than 20k) and
maximum speed (it claims up to 20% better performance than the nearest competitor)
and is suited for fast serialization and deserialization of Simple Object
Access Protocol (SOAP)-based XML objects. For more information, visit http://www.extreme.indiana.edu/xgws/xsoap/xpp/mxp1/.
XSLT Processors
·
Xalan: Xalan is an XSLT processor for
transforming XML documents, from the Apache XML Project. It implements the
W3C Recommendations for XSL Transformations (XSLT) and the XML Path Language
(XPath). It can be used from the command line, in an applet or a servlet,
or as a module in other programs. For more information, visit http://xml.apache.org/xalan-j/index.html.
·
XT: XT is a fast, free implementation
of XSLT in Java. For more information, visit http://www.blnz.com/xt/index.html.
·
SAXON: The SAXON package is a collection
of tools for processing XML documents. It contains an XSLT processor, and
Java libraries for access to the processor from Java applications. For more
information, visit http://saxon.sourceforge.net/.
Java-Specific Document Object Models
These are frameworks that provide a more Java-centric coding approach to
parsing, transforming, etc. than the DOM and SAX interfaces. They can be configured
to use DOM or SAX for parsing, but provide a much more convenient API for
Java programs.
·
JDOM: JDOM is, quite simply, a Java representation
of an XML document. JDOM provides a way to represent that document for easy
and efficient reading, manipulation, and writing. It has a straightforward
API, is lightweight, fast, and is optimized for the Java programmer. It's
an alternative to DOM and SAX, although it integrates well with both of them.
For more information, visit http://www.jdom.org.
·
dom4j: dom4j is an easy to use, open source
library for working with XML, XPath, and XSLT on the Java platform using the
Java Collections Framework and with full support for DOM, SAX, JAXP, TrAX,
and XSLT. dom4j is distributed under an open source,
Apache-style license that does not restrict users to creation of open source
products only. For more information, visit
http://www.dom4j.org.
Other
·
Java XML Pack: The Java XML Pack is an
all-in-one download of Java technologies for XML from SUN. Java XML Pack brings
together several of the key industry standards for XML such as SAX,
DOM, XSLT, SOAP, UDDI, ebXML, and WSDL into one convenient download, thereby
giving developers the technologies needed to get started with web applications
and Web Services. Included in the bundle are: Java API for XML Processing
(JAXP), Java Architecture for XML Binding (JAXB), Java API for XML Messaging
(JAXM), Java API for XML-based RPC (JAX-RPC), and Java API for XML Registries
(JAXR). For more information, visit http://java.sun.com/xml/javaxmlpack.html.
·
Cocoon: Cocoon is an XML framework that
allows easy integrated usage of XML and XSLT technologies for server applications,
around pipelined SAX processing, with a centralized configuration system to
make things simple. It is available for usage under the Apache Software License.
For more information, visit http://xml.apache.org/cocoon/index.html.
There are also lots of utility packages available, such as XML tag libraries
(XTags) for JSP from Jakarta, which give web designers with limited Java knowledge
the full powers of XML processing through simple tags. For more information,
visit
http://jakarta.apache.org/taglibs/doc/xtags-doc/intro.html.
Comments
Be the first to write a comment
You must me logged in to write a comment.