how to save java object into xml from hashtable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gurmeetbedi
    New Member
    • Mar 2008
    • 1

    how to save java object into xml from hashtable

    how to save java object into xml from hashtable?
    any example........ ....
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

    #2
    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.

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      quick example:
      [code=java]
      // Assuming hashtable is in variable hash
      String result = "<hashtable >";
      for (Enumeration e = hash.keys() ; e.hasMoreElemen ts() ;) {
      Object key = e.nextElement;
      result += "<pair>";
      result += "<key>"+key +"</key>";
      result += "<value>"+hash. get(key)+"</value>";
      result += "</pair>";
      }
      result += "</hashtable>

      [/code]

      Comment

      • pronerd
        Recognized Expert Contributor
        • Nov 2006
        • 392

        #4
        Originally posted by jkmyoung
        quick example:
        [code=java]
        // Assuming hashtable is in variable hash
        String result = "<hashtable >";
        for (Enumeration e = hash.keys() ; e.hasMoreElemen ts() ;) {
        Object key = e.nextElement;
        result += "<pair>";
        result += "<key>"+key +"</key>";
        result += "<value>"+hash. get(key)+"</value>";
        result += "</pair>";
        }
        result += "</hashtable>

        [/code]

        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?

        Comment

        Working...