Return-Path: Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: (qmail 22945 invoked from network); 22 Apr 2005 15:23:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 22 Apr 2005 15:23:14 -0000 Received: (qmail 36362 invoked by uid 500); 22 Apr 2005 15:23:30 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 36335 invoked by uid 500); 22 Apr 2005 15:23:29 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 36321 invoked by uid 99); 22 Apr 2005 15:23:29 -0000 X-ASF-Spam-Status: No, hits=0.1 required=10.0 tests=FORGED_RCVD_HELO X-Spam-Check-By: apache.org Received-SPF: neutral (hermes.apache.org: local policy) Received: from csunb0.leeds.ac.uk (HELO csunb0.leeds.ac.uk) (129.11.144.2) by apache.org (qpsmtpd/0.28) with ESMTP; Fri, 22 Apr 2005 08:23:29 -0700 Received: from csunix.leeds.ac.uk (cserv1.leeds.ac.uk [129.11.144.20]) by csunb0.leeds.ac.uk (8.12.11/8.12.11) with ESMTP id j3MFN1Pj012255 for ; Fri, 22 Apr 2005 16:23:01 +0100 Received: from cslin119.csunix.comp.leeds.ac.uk (cslin119.csunix.comp [129.11.146.119]) by csunix.leeds.ac.uk (8.12.2/) with ESMTP id j3MFN0Q9001428 for ; Fri, 22 Apr 2005 16:23:00 +0100 (BST) From: Andy Roberts To: java-user@lucene.apache.org Subject: Digester and simple XML files Date: Fri, 22 Apr 2005 16:26:31 +0000 User-Agent: KMail/1.8 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200504221626.31825.mail@andy-roberts.net> X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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.

some sentences

some more sentences

Now, I want the text that's found between the

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

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? Thanks, Andy public class DigesterTest { private Digester dig; public DigesterTest(File inFile) throws IOException, SAXException { dig = new Digester(); dig.setValidating(false); dig.addObjectCreate("text/body/", Paragraph.class); dig.addCallMethod("text/body/p", "setText", 0); dig.addSetNext("text/body/p", "printParagraph"); System.out.println(inFile); dig.parse(inFile); } public void printParagraph(Paragraph p) { System.out.println(p.getText()); } public static void main(String[] args) { try { new DigesterTest(new File(args[0])); } catch (IOException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } } 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: java-user-unsubscribe@lucene.apache.org For additional commands, e-mail: java-user-help@lucene.apache.org