Introduction to JAXP and Difference between JAXP and JAXB

Previous article was about the introduction to DOM. in this article i will focus on concept of handling XML data using DOM Parser in JAXP.

The Java API for XML Processing (JAXP) is for processing XML data using applications written in the Java programming language. JAXP leverages the parser standards Simple API for XML Parsing (SAX) and Document Object Model (DOM) so that you can choose to parse your data as a stream of events or to build an object representation of it. JAXP also supports the Extensible Stylesheet Language Transformations (XSLT) standard, giving you control over the presentation of the data and enabling you to convert the data to other XML documents or to other formats, such as HTML.

XML Processing in JAVA using DOM :
The Document Object Model (DOM) is a set of interfaces defined by the W3C DOM Working Group. It describes facilities for a programmatic representation of a parsed XML (or HTML) document.

XML Processing using DOM in JAXP
XML Processing using DOM in JAXP

Above diagram shows, how to handle the XML in case of DOM Parser in JAXP.
As shown in above diagram, two classes DocumentBuilderFactory and DocumentBuilder are used to process the XML documents.

Extensible Stylesheet Language Transformations (XSLT):

Extensible Stylesheet Language Transformations
Extensible Stylesheet Language Transformations

A TransformerFactory object is instantiated and used to create a Transformer. The source object is the input to the transformation process. A source object can be created from a SAX reader, from a DOM, or from an input stream.
Similarly, the result object is the result of the transformation process. That object can be a SAX event handler, a DOM, or an output stream.
When the transformer is created, it can be created from a set of transformation instructions, in which case the specified transformations are carried out. If it is created without any specific instructions, then the transformer object simply copies the source to the result.

There is other XML API in Java, “JAXB” stands for the “JAVA Architexture for XML Binding (JAXB)”. It provides the capability of mapping Java classes to XML representations, and simplifies access to an XML document for a Java program. The first step in this process is to bind the XML Schema into a set of Java classes that represents the schema. JAXB provides two main features:

  • The ability to marshal Java objects into XML
  • The ability to unmarshal XML back into Java objects.

JAXB is one of the APIs in the Java EE platform, and is part of the Java Web Services Development Pack (JWSDP). It is also one of the foundations for WSIT. JAXB is part of SE version 1.6.





Related Posts


3 responses to “Introduction to JAXP and Difference between JAXP and JAXB”

  1. […] In this article, i am going to use the Swing for the UI purpose and for the XML validation against its schema i will use DOM parser as well as SAX Parser. previously we have already seen that how these parsers works in detail. […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading