Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to read XML in Java

Tags:

java

xml

From some of our other application i am getting XML file.

I want to read that XML file node by node and store node values in database for further use.

So, what is the best way/API to read XML file and retrieve node values using Java?

like image 812
Romani Avatar asked Aug 25 '11 09:08

Romani


People also ask

What is the best way to view an XML file?

View an XML file in a browser If all you need to do is view the data in an XML file, you're in luck. Just about every browser can open an XML file. In Chrome, just open a new tab and drag the XML file over. Alternatively, right click on the XML file and hover over "Open with" then click "Chrome".

Which XML parser is best in Java for large files?

DOM Parser is faster than SAX Parser. Best for the larger sizes of files.

Can you use XML with Java?

XML provides a universal syntax for Java semantics (behavior). Simply put, this means that a developer can create descriptions for different types of data to make the data behave in various ways with Java programming code, and can later repeatedly use and modify those descriptions.


1 Answers

There are various tools for that. Today, I prefer two:

  • Simple XML
  • JAXB
  • StAX

Here is a good comparison between the Simple and JAXB: http://blog.bdoughan.com/2010/10/how-does-jaxb-compare-to-simple.html

Personally, I like Simple a bit better because support by Niall is excellent but JAXB (as explained in the blog post above) can produce better output with less code.

StAX is a more basic API which allows you to read XML documents that simply don't fit into RAM (neither Simple nor JAXB allow you to read an XML document "object by object" - they will always try to load everything into RAM at once).

like image 64
Aaron Digulla Avatar answered Oct 02 '22 11:10

Aaron Digulla