Use Digester to parse an XML document example
l_walker 2003-5-2
Keywords: XML, Digester, resolution
abstract:
This paper briefly introduces and exemplifies how to use Apache's Digester to parse the XML document.
1 Overview
Analysis of the XML document has a lot of methods, there are also a lot of toolkits available, here is the Digester from Apache Jakarta, which is very convenient to use it to parse the XML file without excessive care of the specific parsing process.
DiGester first appeared in Struts, later followed by the development of Struts and its publicity, it was reached in Commens, and its underlying achieved SAX analysis. The current version is: 1.5
2. Text
1. Installation and configuration
Using Digester requires the following packages:
Digester, BeanUtils, Collectes, Commens-Logging, and an XML parser that follows SAX (Simple API for XML 2.0 or JAX (Java API for XML Parsing) 1.1 specification, such as Xerces. See the address of the download address. If you need to use the log4j as a log output, please also download it.
Pack the downloaded ZIP and copy the JAR file into the lib directory of your project file, and contain the path to the JAR file described above in the project classpath.
Create a commons-logging.properties file in your engineering class (such as Classes), the content is:
Org.apache.commons.logging.log = org.apache.commons.logging.Impl.log4jlogger
This indicates that the system will use log4j as a log output, then build a log4j.proerties file, please refer to the log4j document or other reference.
2. XML file
In the engineering directory, create a new XML file, the example uses module.xml, see below:
Skyhome of www.skyinn.org 2.0.1 l_wakler walker@skyinn.org 2003-04-30 RequestPath = "/ home" actionclass = "org.skyinn.action.globalact"> requestPath = "/ forum" actionclass = "Org.skyinn.Action.forumaction">
3. Analysis XML document
Digester's use is quite simple, please see the comments in the following Sampledigester class, no longer 拗 拗:
/ * ================================================================================================================================================================ ============ * Copyright: www.skyinn.org (c) 2002 - 2003 All rights reserved. * File: org.skyinn.quasar.config.sampledigester * inculde: Sampledigester * Modify Records * Date author content * ============================================== =============== * 2003-5-1 walker create class * ========================== ============================================ * / package org.skyinn.quasar.config; import org.apache .commons.digester.digester; import org.xml.sax.saxexception; import org.skyinn.quasar.Action.actionmapping; import java.io ioException; / ** * Digester parsing XML sample program. * * @Author walker (walker@skyinn.org) * * References: * Learning and Using Jakarta Digester * Digester simplified processing XML configuration file * / public class SampleDigester {private String configFile; public void setConfigFile (final String configFile) { THIS.CONFIGFILE = ConfigFile;} / ** * Start resolution.