简体   繁体   English

如何通过Java生成xml文件?

[英]How to generate xml file by Java?

I have to generate huge and quite complex xml files by Java. 我必须通过Java生成巨大且非常复杂的xml文件。 I have to fetch the data from a Oracle database. 我必须从Oracle数据库中获取数据。 What I really don't know is a proper and reliable way to this? 我真的不知道这是正确而可靠的方法吗? I could of course create a String and concatenate all the tags, attributes and data but it doesn't feel right. 我当然可以创建一个String并连接所有标签,属性和数据,但是感觉不对。 I guess this is a quite common task and there are many established ways to this by Java. 我想这是一个很常见的任务,Java有许多建立起来的方法。 My question is what is the best way to this? 我的问题是最好的方法是什么? What is your suggestion? 你有什么建议? Thank you for any clues... 谢谢你的线索...

You could use JAXB for building XML out of structured objects that are a result of querying your data store. 您可以使用JAXB从查询数据存储结果的结构化对象中构建XML。

If your object hierarchy is not complex, you can use Oracle's capability to generate results in XML . 如果对象层次结构不复杂,则可以使用Oracle的功能以XML生成结果

There are several options for object to xml transformation. 有多种object to xml转换的选项。

I would personally suggest JAXB for easy of use and saxparser for performance centric application. 我个人建议使用JAXB易于使用,建议使用saxparser以性能为中心的应用程序。

您可以使用JAXP(用于XML解析的Java API)创建XML结构。它具有您想要的所有功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM