0

Possible Duplicate:
Comparison of XML parsing APIs on the Java SE platform

I am trying to code an XML parser using Java and for that there's a lot of API that treat xml such as sax, jdom, xerces, ... and I did not know which one to use.

Community
  • 1
  • 1
morfioce
  • 1,107
  • 2
  • 9
  • 12
  • 1
    I don't know either, it depends on your requirements... I'd have a look at those bundled with your JDK (DOM, SAX, STAX). – home Feb 13 '12 at 16:22
  • Do a quick read on sax vs dom xml parsing and determine your needs. Then determine which parsing library you want. Basically, if you have small xml documents, xerces dom parser should be fine. If you have peculiarities where xerces isn't fine, then you need to describe your particular problem in greater detail. – ccoakley Feb 13 '12 at 16:26
  • This is answered in this post: [Where I can find a detailed comparison of Java XML frameworks?](http://stackoverflow.com/questions/3855324/where-i-can-find-a-detailed-comparison-of-java-xml-frameworks) – Thijs Feb 13 '12 at 16:31

1 Answers1

2

There are three API choices and for each of them are multiple implementations available

SAX (Simple API for XML) in this model the parser calls callback functions you have to supply for each element or attribute it encounters. The SAX API is read only, you will need an other API for writing.

DOM in this model the parser generates a DOM which is a hierarchy of objects representing the structure of the XML document. This method can require lots of memory for large documents and the DOM tree isn't that easy to use. It most useful when you have to handle documents with unknown contents. The DOM can both be read and written.

JAXB allows you to use your own objects and by annotating them you can map your objects to XML. It can both read and write. This one requires the least amount of code.

Eelke
  • 20,897
  • 4
  • 50
  • 76