原文位址: http://kushanxp.blogspot.com/2011/02/hello-world-with-apache-commons.html
This example will shows how to get started with Apache Commons Digester.
What is Apache Commons Digester?
Simply, you can use this to read a XML file against a particular pattern (say, particular tag in XML file) and if it found, you can trigger some actions (say, a method, so that method will be called if that pattern is matched)
So Let's start then,
You shoud have JDK 1.5 installed and need to download several libraries, which are,
1. Apache Commons Digester Library.
2. Apache Commons Logging.
3. Apache Commons BeanUtils.
I'm using eclipse as the IDE, so here we go,
Create a Java project from eclipse and add those downloaded libraries to that and set the build path correctly.
Create a XML file with following contents:
Create a Java class with a main method, Let's call this as DigesterTest.java
add following method there,
Here is the directory structure of my eclipse project,
[img]
https://lh6.googleusercontent.com/-hqqGTdt1NxM/TWOADmOgMeI/AAAAAAAAAr0/VqIKa8IHSqk/s1600/digester.PNG
[/img]
4 comments:
kris said...
Nice stuff, keep them coming.. :)
March 1, 2011 2:18 AM
Kushan Jayathilake said...
:) Thank you..
March 1, 2011 9:38 AM
Anonymous said...
I think that xpath+extended vtd-xml serve a better option in terms of performance and ease of use
March 1, 2011 2:33 PM
Kushan Jayathilake said...
Yeah, it can be used to read a XML, but can it be given a set of rules (rule types and the count of rules) and a method to call if the rules are match?
March 1, 2011 2:57 PM