以前写的一个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;
}
* 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;
}
解决方案 »
- 如何用JavaScript实现返回到上一页?
- struts2上传文件,在action中接手的文件为空怎么回事
- 通过Axis2-1.4.1调用C#的asmx的web service
- 最重要的 10 几个J2EE 最佳实践[z] --- 有的内容过时了
- 急啊,在线等好心人!怎么在eclipse里打开tomcat!
- struts的<html:radio>标签问题
- spring data jpa 事务问题 Executing an update/delete query
- 我想学java编程,请问用什么编程环境,最好简体中文
- j2ee1.3启动错误,问了好久了也没解决,实在是受不了啊,在线等待~~~
- 通过action调用antion和通过页面上标签调用有何不同
- 怎样在数据表中得到Insert后的自动增量字段的值?
- java如何读http://expert.csdn.net/Expert/PostNew.asp?room=5404的网页源码?
公司不会给这个时间的,呵呵
换个做法,一样可以实现!
谢谢楼上的了
放分