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;
}
解决方案 »
- 关于进程间通信方式、web http server 间的通信方式
- Eclipse+Lomboz+Tomcat配置的一个诡异问题!!!!
- 大家来看看这个uml图是不是正确的画法
- WAS集群。WEB系统无法登录!!请求高人解答!
- 请教
- 请问如何用java生成一个word文件,并对其内容进行操纵,有没有成熟的包有类似的功能?
- 使用JDBC和SqlServer 2000连接的时候,会出现以下错误:Error establishing socket.java.sql.sqlException
- 请帮一下, tomcat 5.0.25 配置连接池时总是报错,不能取得连接,以下是配置文件,测试文件和错误信息.
- sql语句order by多条件排序
- sqlserver插入2892条出错
- 关于JBuilder 8 + Weblogic 7.01调试
- 如何用java实现xml里数学公式的解析和计算?
我的最终目的是想在javabean生成一棵xml树。这样好让servlet调用。请问需要怎么做。