You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Sudhi Shetty <re...@gmail.com> on 2008/12/30 17:07:54 UTC
[Digester] Parse into HashMap using Commons Digester
I need to parse a XML file having the following format(Not posting the
actual XML due to confidentiality reasons but repesenting the problem
in a sample format) :
<movielibraries>
<library name="Libra">
<movie name="XYZ">
<releasedate date="ABC"/>
<director name="SDR"/>
</movie>
</library>
<library>
......
</library>
</movielibraries>
I want to parse this into a HashMap where in the 'key' is the library
name and value is 'List' of Movie instances for that library.
class Movie {
String name;
Date releaseDate;
String director
}
Is it possible to achieve this using Digester?
Re: [Digester] Parse into HashMap using Commons Digester
Posted by Tobias Demuth <su...@cinebet.de>.
Sudhi Shetty schrieb:
> I want to parse this into a HashMap where in the 'key' is the library
> name and value is 'List' of Movie instances for that library.
> class Movie {
> String name;
> Date releaseDate;
> String director
> }
>
Just push the HashMap on the stack before calling parse(). For <library>
I would probably define my own rule, which would put an empty
ArrayList<Movie> with the name of library as key into that hashmap.
Constructing the Movies and adding them to the list should be quit
simple then.
kind regards
Tobias
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [Digester] Parse into HashMap using Commons Digester
Posted by Rahul Akolkar <ra...@gmail.com>.
On Tue, Dec 30, 2008 at 11:07 AM, Sudhi Shetty <re...@gmail.com> wrote:
> I need to parse a XML file having the following format(Not posting the
> actual XML due to confidentiality reasons but repesenting the problem
> in a sample format) :
>
> <movielibraries>
> <library name="Libra">
> <movie name="XYZ">
> <releasedate date="ABC"/>
> <director name="SDR"/>
> </movie>
> </library>
> <library>
> ......
> </library>
> </movielibraries>
>
> I want to parse this into a HashMap where in the 'key' is the library
> name and value is 'List' of Movie instances for that library.
> class Movie {
> String name;
> Date releaseDate;
> String director
> }
> Is it possible to achieve this using Digester?
<snip/>
Yes. Please see the developer guide [1] and examples [2] for details,
and let us know if you have specific questions.
-Rahul
[1] http://commons.apache.org/digester/commons-digester-1.8/docs/api/org/apache/commons/digester/package-summary.html#package_description
[2] http://svn.apache.org/repos/asf/commons/proper/digester/trunk/src/examples/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org