public class MyMap()
{
private Map _mymap ;
public MyMap()
{
_mymap = new HashMap() ;
}
public void addBook(Book mybook)
{
_mymap.put(mybook.getTitle(), mybook) ;
}
}
public class MyDigester()
{
public void load() throws IOException, SAXException
{
Digester d = new Digester()
d.addObjectCreate("library", "MyMap") ;
d.addObjectCreate("library/book", "Book") ;
d.addBeanPropertySetter("library/book/title", "setTitle") ;
d.addBeanPropertySetter("library/book/author", "setAuthor")
;
d.addSetNext("library/book", "addBook") ;
File input = new File("myxmlfile") ;
MyMap m = (MyMap) d.parse(input) ;
}
}
Regards,
Phillip Qin
"This Guy Thinks He Knows Everything"
Canadian Shareowner
121 Richmond Street W, 7th Floor
Toronto, ON M5H 2K1
(416) 595-9600 ext 291
-----Original Message-----
From: Baltz, Kenneth [mailto:[EMAIL PROTECTED]]
Sent: December 18, 2002 5:06 PM
To: Jakarta Commons Users List
Subject: [Digester]How to populate a HashMap?
How would I go about doing the following using Digester?
Given XML as such:
<library>
<book>
<title>TITLE TEXT</title>
<author>AUTHOR TEXT</author>
</book>
<!-- multiple books to follow -->
<book>
...
</book>
</library>
Assume there's a Book bean with title and author properties.
How can I make the digester read in the books and put them in a HashMap by
title? I can't see how to pass the object on the top of the stack as an
argument to a method call.
K.C. Baltz