Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Digester Problem

Neha Kathuriaa
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to create a simple digester class .I tried the following example given on Apache site.
package mypackage;
public class Foo {
public void addBar(Bar bar);
public Bar findBar(int id);
public Iterator getBars();
public String getName();
public void setName(String name);
package mypackage;
public class Bar {
public int getId();
public void setId(int id);
public String getTitle();
public void setTitle(String title);
and you wish to use Digester to parse the following XML document:
<foo name="The Parent">
<bar id="123" title="The First Child"/>
<bar id="456" title="The Second Child"/>
A simple approach will be to use the following Digester in the following way to set up the parsing rules, and then process an input file containing this document:

Digester digester = new Digester();
digester.addObjectCreate("foo", "mypackage.Foo");
digester.addObjectCreate("foo/bar", "mypackage.Bar");
digester.addSetNext("foo/bar", "addBar", "mypackage.Bar");
Foo foo = (Foo) digester.parse();
This was working for me. Now I want to create a digester class which can read tags from xml file. But I don't want to give the matching patterns like this digester.addObjectCreate("foo", "mypackage.Foo");I want to read all the custom tags in xml in generakized manner.Can anybody give me a solution to this?
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic