怎么样把生成的document保存为文件呢?

0_0 2004-05-04 01:35:27
怎么样把生成的document令保存为文件呢?
我就是想看我生成的document得内容。我用java谢谢
...全文
302 7 点赞 打赏 收藏 举报
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
qujihe 2004-06-09
public void outputXMLToFile(Document doc, String fileName)
{
try {
FileWriter writer = new FileWriter(fileName);
//Pay attention to the OutputFormat constructor, which set the GB2312
org.apache.xml.serialize.OutputFormat outputFormat =
new org.apache.xml.serialize.OutputFormat(doc, "GB2312", true);

org.apache.xml.serialize.XMLSerializer serializer =
new org.apache.xml.serialize.XMLSerializer(writer, outputFormat);
serializer.serialize(doc);
writer.close();
}
catch (IOException ioe) {
;
}
}
  • 打赏
  • 举报
回复
jdk150 2004-05-05
//doc is the document you want to save

TransformerFactory tFactory =TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new java.io.File("links.xml"));
transformer.transform(source, result);
  • 打赏
  • 举报
回复
0_0 2004-05-04
detail plz
  • 打赏
  • 举报
回复
jeasoyang 2004-05-04
CSDN FANS自己的乐园

shcsdn.35sw.com
bbs.35sw.com
www.35sw.com
www.vhostzone.com
  • 打赏
  • 举报
回复
rombus 2004-05-04
io
  • 打赏
  • 举报
回复
0_0 2004-05-04
没看懂 :( 有没有简单的 把document保存为.xml文件
  • 打赏
  • 举报
回复
saucer 2004-05-04
what is this document? how is it created?

see

http://www.cafeconleche.org/books/xmljava/chapters/ch13s02.html

from
Processing XML with Java
http://www.cafeconleche.org/books/xmljava/

  • 打赏
  • 举报
回复
相关推荐
发帖
XML/XSL
加入

8854

社区成员

XML/XSL相关问题讨论专区
申请成为版主
帖子事件
创建了帖子
2004-05-04 01:35
社区公告
暂无公告