6.1. Obtaining Jakarta Commons Digester
Problem
You need to use Jakarta Commons Digester to quickly parse an XML document into a set of objects.
Solution
You must download the latest version of Commons Digester and place
the Commons Digester JAR
in your
project’s classpath. Following the steps outlined in
Recipe 1.1, download Commons Digester 1.5
instead of Commons Lang. Uncompress the distribution archive and
place commons-digester.jar
in your classpath.
Commons Digester depends on Commons BeanUtils, Commons Logging, and
Commons Collections. To download dependencies, see Recipe 3.2, Recipe 5.1, and Recipe 7.9.
Discussion
Commons Digester started as a part of Jakarta Struts, and it was
moved to the Jakarta Commons project by way of the Commons Sandbox in
early 2001. Digester is the mechanism Struts uses to read XML
configuration; struts-config.xml
is the main
configuration point for Jakarta Struts, and it is converted to a set
of objects using the Digester. The Digester’s most
straightforward application is the mapping of an XML document to a
set of Java objects, but, as shown in this chapter and Chapter 12, Digester can also be used to create a
simple XML command language and search index. Digester is a shortcut
for creating a SAX parser. Almost anything you can do with a SAX
parser can be done with Jakarta Commons Digester.
If you have a Maven project that needs to use Commons Digester, add a
dependency on Commons Digester 1.5 with the following section in
project.xml
:
<dependencies> ...
Get Jakarta Commons Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.