469,336 Members | 5,643 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

how to save java object into xml from hashtable

how to save java object into xml from hashtable?
any example............
Mar 31 '08 #1
3 5353
pronerd
392 Expert 256MB
This should be posted in a forum for Java. Creating XML from Java is a pretty basic process. Google will be able to provide you with wealth of examples.
Apr 1 '08 #2
jkmyoung
2,057 Expert 2GB
quick example:
Expand|Select|Wrap|Line Numbers
  1. // Assuming hashtable is in variable hash
  2. String result = "<hashtable>";
  3. for (Enumeration e = hash.keys() ; e.hasMoreElements() ;) {
  4.   Object key = e.nextElement; 
  5.   result += "<pair>";
  6.   result += "<key>"+key+"</key>";
  7.   result += "<value>"+hash.get(key)+"</value>";
  8.   result += "</pair>";
  9. }
  10. result += "</hashtable>
  11.  
  12.  
Apr 1 '08 #3
pronerd
392 Expert 256MB
quick example:
Expand|Select|Wrap|Line Numbers
  1. // Assuming hashtable is in variable hash
  2. String result = "<hashtable>";
  3. for (Enumeration e = hash.keys() ; e.hasMoreElements() ;) {
  4.   Object key = e.nextElement; 
  5.   result += "<pair>";
  6.   result += "<key>"+key+"</key>";
  7.   result += "<value>"+hash.get(key)+"</value>";
  8.   result += "</pair>";
  9. }
  10. result += "</hashtable>
  11.  
  12.  

Hmmmm.... This brings up another good question. What Java object type are you wanting to transfer the Hashtable data to. This code will produce a string object. Will that work, or will you need it in a XML element or node object?
Apr 1 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Chandu | last post: by
3 posts views Thread by Fred | last post: by
reply views Thread by dotnet_vb_newbie | last post: by
16 posts views Thread by coosa | last post: by
madhoriya22
21 posts views Thread by madhoriya22 | last post: by
reply views Thread by abhishekbrave | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.