Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HashMap to xml

843834Aug 18 2004 — edited Aug 18 2004
I am new to java and xml. I've been trying to figure out a way to convert a HashMap into an XML string. I download castor and have been playing around w/ the marshallar but am having no luck.

I create a hashmap as such:
java.util.HashMap hm = new java.util.HashMap();
hm.put("key","value");
hm.put("key1","value1");

then i attempt to send it to xml as such:
Marshaller m = null;
try{m=new Marshaller(new OutputStreamWriter(System.out));}catch(java.io.IOException ioe){
System.out.println(ioe);
}
try{m.marshal(hm);}catch(org.exolab.castor.xml.ValidationException ve){
System.out.println(ve);
}catch(org.exolab.castor.xml.MarshalException me){
System.out.println(me);
}

In System.out this is all i get:

<?xml version="1.0" encoding="UTF-8"?>
<hash-map empty="false" empty="false"/>

Any thoughts?

Brandon
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 15 2004
Added on Aug 18 2004
1 comment
391 views