Wednesday, July 22, 2015

What is the difference between JAXB and JAXP? (98/285 technotes for 2015)

JAXP (Java API for XML Processing) is a rather outdated umbrella term covering the various low-level XML APIs in JavaSE, such as DOM, SAX and StAX.

  1. Create a SAX Parser or DOM Parser and then PArse the data, if we use DOM, it may be memory intensive if the document is too big. Suppose if we use SAX parser, we need to identify the beginning of the document. When it encounters something significant (in SAX terms, an “event”) such as the start of an XML tag, or the text inside of a tag, it makes that data available to the calling application.
  2. Then Create a content handler that defines the methods to be notified by the parser when it encounters an event. These methods, known as callback methods, take the appropriate action on the data they receive.

JAXB (Java Architecture for XML Binding) is a specific API (the stuff under javax.xml.bind) that uses annotations to bind XML documents to a java object model.

  1. Bind the schema for the XML document.
  2. Unmarshal the document into Java content objects. The Java content objects represent the content and organization of the XML document, and are directly available to your program. After unmarshalling, your program can access and display the data in the XML document simply by accessing the data in the Java content objects and then displaying it. There is no need to create and use a parser and no need to write a content handler with callback methods. What this means is that developers can access and process XML data without having to know XML or XML processing

References: 

http://stackoverflow.com/questions/2801502/what-is-the-difference-between-jaxp-and-jaxb

No comments: