471,896 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,896 software developers and data experts.

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 5459
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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.