Data::Dumper and XML::Simple in Java

R

rc

Hello

I've used Perl a lot, but now i have to use Java in some projects. The
two things i miss most are:

Data::Dumper - a Perl module that can dump the content of any nested
data structure to the console

XML::Simple - a Perl module that reads a xml file and puts all of the
content in a nested data structure consisting of arrays and hashmaps
(in a single instruction like $xml = XMLIn("/tmp/file.xml"), way
easier than Jakarta Digester and the other stuff i've seen so far in
Java

Is there something similar in Java?

regards
 
D

David Hilsee

rc said:
Hello

I've used Perl a lot, but now i have to use Java in some projects. The
two things i miss most are:

Data::Dumper - a Perl module that can dump the content of any nested
data structure to the console

XML serialization of java beans is provided in Java 1.4. See
java.beans.XMLEncoder. You may find it to be a suitable replacement for
Data::Dumper.
XML::Simple - a Perl module that reads a xml file and puts all of the
content in a nested data structure consisting of arrays and hashmaps
(in a single instruction like $xml = XMLIn("/tmp/file.xml"), way
easier than Jakarta Digester and the other stuff i've seen so far in
Java

In this case, I don't know of anything that does what you want, unless
java.beans.XMLDecoder fits the bill.

The exact functionality that was present in Perl is not present in Java
because it is very rare for a programmer to have a data structure composed
entirely of arrays/ArrayLists/HashMaps/other standard collections. After
diving 2 or 3 levels into the data structure, such a concoction can be hard
to follow. Therefore, for readability's sake, at some point during the
nesting of data structures, there is likely to be an instance of a class
that is not merely a collection class provided by the standard library. If
it follows the java beans naming conventions, then it is possible that
XMLEncoder and XMLDecoder will work reliably. Those classes are the closest
matches to the Perl modules that you miss. There may be some third party
library that provides what you want, but I am not aware of it.
 
T

Tor Iver Wilhelmsen

David Hilsee said:
In this case, I don't know of anything that does what you want, unless
java.beans.XMLDecoder fits the bill.

It doesn't - XMLDecoder is for "decoding" XML written using
XMLEncoder, and relies on that particular syntax, and that the
particular classes exist as JavaBeans.

What the poster probably wants is something that builds a "nested
dictionary" from the XML. I don't think there's something like that in
the standard libraries. However, it's relatively easy to make using a
SAX parser.
 
C

Chris Uppal

Tor said:
What the poster probably wants is something that builds a "nested
dictionary" from the XML. I don't think there's something like that in
the standard libraries. However, it's relatively easy to make using a
SAX parser.

Or one could provide Facade that adapted a DOM implementation to look like
nested java.util.Map-s.

-- chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top