在Java中创建XML文件的最佳方式是什么?

时间:2022-09-15 19:51:41

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.

我们目前正在使用dom4j创建XML文件。不过,我想现在有更好的了。如果我们是Java 1.6或更高版本,那么在编写XML文件时最好的(运行时最快,使用起来简单)类(es)是什么呢?

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.

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

thanks - dave

谢谢——戴夫

3 个解决方案

#1


4  

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.

如果您只想编写一个XML文档,该文档对元素、属性和其他文档组件的创建具有精确的控制,您可以使用来自StAX API的XMLStreamWriter。

#2


4  

I guess you know about StAX and the SAX framework.
Just mentioning them in case you haven't considered them.

我想你应该知道StAX和SAX框架。如果你还没考虑过,就提出来。

http://docs.oracle.com/javase/tutorial/jaxp/stax/example.html#bnbgx

http://docs.oracle.com/javase/tutorial/jaxp/stax/example.html bnbgx

http://docs.oracle.com/javaee/1.4/tutorial/doc/JAXPXSLT5.html

http://docs.oracle.com/javaee/1.4/tutorial/doc/JAXPXSLT5.html

#3


3  

My 2 cents goes to java-xmlbuilder. Only for building though. It's hell a lot less complicated than JAXP.

我的2美分给了java-xmlbuilder。只有构建。它比JAXP要简单得多。

#1


4  

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.

如果您只想编写一个XML文档,该文档对元素、属性和其他文档组件的创建具有精确的控制,您可以使用来自StAX API的XMLStreamWriter。

#2


4  

I guess you know about StAX and the SAX framework.
Just mentioning them in case you haven't considered them.

我想你应该知道StAX和SAX框架。如果你还没考虑过,就提出来。

http://docs.oracle.com/javase/tutorial/jaxp/stax/example.html#bnbgx

http://docs.oracle.com/javase/tutorial/jaxp/stax/example.html bnbgx

http://docs.oracle.com/javaee/1.4/tutorial/doc/JAXPXSLT5.html

http://docs.oracle.com/javaee/1.4/tutorial/doc/JAXPXSLT5.html

#3


3  

My 2 cents goes to java-xmlbuilder. Only for building though. It's hell a lot less complicated than JAXP.

我的2美分给了java-xmlbuilder。只有构建。它比JAXP要简单得多。