lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Roberts <>
Subject Digester and simple XML files
Date Fri, 22 Apr 2005 16:26:31 GMT
Hi all,

Just been playing with Digester after reading chapter 7 in LIA. Seems to fit 
my needs as I have a relatively simple XML structure. 

		<!-- meta data about the file here. This is not important to me. -->

			<!-- info here too but it's nothing I care about -->
			<p>some sentences</p>
			<p>some more sentences</p>

Now, I want the text that's found between the <p> tags within the body 
section. So, I wrote a little test class using a largely bastardised version 
of DigesterXMLHandler from LIA.

I'm a tad confused to say the least. I create a Paragraph object upon seeing 
text/body. Then, call setText when I see the next <p> tag. And that's all I 
want per object, so I've added the addSetNext to call printParagraph which I 
hope prints the previous paragraph contents. But it doesn't!

My code looks so wrong but I've been hacking at it for a while with little 
fun. Any suggestions?


public class DigesterTest {
    private Digester dig;
    public DigesterTest(File inFile) throws IOException, SAXException {
        dig = new Digester();
        dig.addObjectCreate("text/body/", Paragraph.class);

        dig.addCallMethod("text/body/p", "setText", 0);
        dig.addSetNext("text/body/p", "printParagraph");
    public void printParagraph(Paragraph p) {
    public static void main(String[] args) {
        try {
            new DigesterTest(new File(args[0]));
        } catch (IOException e) {
        } catch (SAXException e) {
    public class Paragraph {
    	private String text;
    	public Paragraph() {
    	public String getText() {
    	    return text;
    	public void setText(String inText) {
    	    if (inText != null) {
    	        text = inText;


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message