在Java中创建XML文件的最佳方法是什么? [英] What is the best way to create XML files in Java?

查看:259
本文介绍了在Java中创建XML文件的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前正在使用dom4j来创建XML文件。但是,我猜现在有更好的东西了。如果我们是Java 1.6或更高版本,那么在写出XML文件时使用的最好(运行时最快,使用简单)类。

We are presently using dom4j to create XML files. However, I'm guessing there's something better now. If we are Java 1.6 or later, what is the best (fastest when running, simple to use) class(es) to use when writing out an XML file.

I不需要构建DOM然后编写整个DOM。我只需要在将它们传递给类时写出元素/属性的东西。

I do not need to build a DOM and then write the entire DOM. I just need something that will write out the elements/attributes as I pass them to the class.

谢谢 - 戴夫

推荐答案

如果您只想编写一个XML文档,可以精确控制元素,属性和其他文档组件的创建,您可以使用 XMLStreamWriter

If you just want to write an XML document having exact control over the creating of elements, attributes and other document components, you may use the XMLStreamWriter from the StAX API.

这篇关于在Java中创建XML文件的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆