HashMap to xml
843834Aug 18 2004 — edited Aug 18 2004I 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