API for XML programming [closed]
Is there any good Java API that i can use to create XML documents where i can eliminate all the boilerplate code using SAX and DOM parsers. I am also looking for an API that can create CSV file from xml document. Suggestions can make my work faster..
It looks like you're asking two questions here:
Check out the excellent dom4j library for simplified XML document creation.
See the Apache Commons CSV project and SuperCSV.
dom4j or JDOM for simple XML. I've never done anything with CSV in Java, but CSV isn't very complex, and a Google search turned up some promising results.
Check out the StAX API, which is located in package `javax.xml.stream´. It's been included in Java SE since version 1.6 and as far as I know is the only non-third-party Java API that can be used to write documents in an orderly fashion. I'm not certain why you mention boilerplate code of SAX and DOM parsers, since those are for reading XML, not writing.
All the recommendations by others here are good too, but before you start using an object-model approach like JDOM, keep memory overhead in mind. You could run into trouble for large documents.
Finally, should the intended documents lend themselves to this, you could have a more Java-centric approach through JAXB. This won't be ideal for any sort of XML, mind you. It depends on what you wish to do with it. Again, memory usage will be higher than streaming small bits at a time, although JAXB uses StAX when un/marshalling.
XStream is not SAX based, its stream based but you do almost everything using annotations. Very good and easy to use.
http://x-stream.github.io/
精彩评论