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

0_0 2004-05-04 01:35:27
怎么样把生成的document令保存为文件呢?
我就是想看我生成的document得内容。我用java谢谢
...全文
441 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
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/

8,909

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧