以前写的一个API,你参考参考吧   /**
    * Transform a java.util.Hashtable object to a org.xml.dom.Document object.
    * NOTE: The specified Hashtable's keys must be String type and values's
    * fact type must be String type.
    * @param dataSet
    * @param rootName
    * @return Document
    */
   public static synchronized Document getDocument(java.util.Hashtable dataSet, String rootName) 
   {
    Document dataDoc = null;
    
    try 
    {
      //Create the document builder
      DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder docBuilder = dbFactory.newDocumentBuilder();
         
      //Create the new document(s)
      dataDoc = docBuilder.newDocument();
      Element dataRoot = dataDoc.createElement(rootName);
      dataDoc.appendChild(dataRoot);
      
      Enumeration keyEmr = dataSet.keys();
      Enumeration valueEmr = dataSet.elements();
      
      while (keyEmr.hasMoreElements())
      {
        String sKey = (String)keyEmr.nextElement();
        Recorder.myLog.debug("sKey = "+sKey);        
        
        Element prop = dataDoc.createElement(sKey);
        dataRoot.appendChild(prop);        
        
        Object oValue = valueEmr.nextElement();
        Recorder.myLog.debug("oValue's true type = "+oValue.getClass().getName());
        
        if (oValue.getClass().getName().equals(Hashtable.class.getName()))
        {
          Hashtable hValue = (Hashtable)oValue;
          Document tempDoc = getDocument(hValue, rootName);
          
          NodeList tempNl = tempDoc.getDocumentElement().getChildNodes();
          int nlLen = tempNl.getLength();
          Recorder.myLog.debug("nlLen = "+nlLen);
          for (int i=0; i<nlLen; i++)
          {
            Node tempN = tempNl.item(i);
            Recorder.myLog.debug("Node = "+tempN);
            prop.appendChild(dataDoc.importNode(tempN, true));
          }
          
        }
        else
        {
          String sValue = (String)oValue;
          Recorder.myLog.debug("sValue = "+sValue);
          Node tValue = dataDoc.createTextNode(sValue);
          prop.appendChild(tValue);
        }
      }      
    }
    catch (Exception e)
    {
      Recorder.myLog.debug("Caught an exception : ", e);
    } 
    
    return dataDoc;    
   }