1、不要用Crimson,过时而且效率低,使用xerces代替;
2、输出DOM Document不能简单使用Java IO,应如下: /**
* 将DOM的Document对象写入文件。
* @param name 文件名称。
* @param document DOM的Document对象。
* @return 成功返回0
* @throws java.io.IOException 写文件时出错。
*/
public static final synchronized long writeXmlFile( java.lang.String name,
org.w3c.dom.Document document )
throws javax.xml.transform.TransformerConfigurationException,
javax.xml.transform.TransformerException
{
DOMSource doms = new DOMSource( document );
File file = new File( name );
StreamResult result = new StreamResult( file );
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
Properties properties = transformer.getOutputProperties();
properties.setProperty( OutputKeys.ENCODING, "GB2312" );
properties.setProperty( OutputKeys.METHOD, "xml" );
properties.setProperty( OutputKeys.INDENT, "yes" );
transformer.setOutputProperties( properties );
transformer.transform( doms, result );
return 0;
}
2、输出DOM Document不能简单使用Java IO,应如下: /**
* 将DOM的Document对象写入文件。
* @param name 文件名称。
* @param document DOM的Document对象。
* @return 成功返回0
* @throws java.io.IOException 写文件时出错。
*/
public static final synchronized long writeXmlFile( java.lang.String name,
org.w3c.dom.Document document )
throws javax.xml.transform.TransformerConfigurationException,
javax.xml.transform.TransformerException
{
DOMSource doms = new DOMSource( document );
File file = new File( name );
StreamResult result = new StreamResult( file );
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
Properties properties = transformer.getOutputProperties();
properties.setProperty( OutputKeys.ENCODING, "GB2312" );
properties.setProperty( OutputKeys.METHOD, "xml" );
properties.setProperty( OutputKeys.INDENT, "yes" );
transformer.setOutputProperties( properties );
transformer.transform( doms, result );
return 0;
}
解决方案 »
- spring发送邮件失败
- java程序打包成jar后,怎样安装成windows service,并开机自启?
- 关于spring容器无法装载bean的问题!!!!!!!
- jsp 后退问题
- 我在win2003 与win2000中安装不上tomcat 5.0,请求帮助?
- 请大家帮忙看段程序——急!急!
- 请问struts怎么和oracle相连?尤其是 struts-config的配置!
- 请问在weblogic6.1下配置struts,有什么特殊的配置需要吗??
- entity ejb 是CMP还是BMP好啊
- EJB的基本问题,熟悉EJB的朋友请进
- 关于JBuilder 8 + Weblogic 7.01调试
- 如何用java实现xml里数学公式的解析和计算?
我的最终目的是想在javabean生成一棵xml树。这样好让servlet调用。请问需要怎么做。