Sunday, April 3, 2011

Java API for XML Processing (JAXP)

The Java API for XML Processing, or JAXP, is one of the Java XML programming APIs. It provides the capability of validating and parsing XML documents. The three basic parsing interfaces are:
* the Document Object Model parsing interface or DOM interface
* the Simple API for XML parsing interface or SAX interface
* the Streaming API for XML or StAX interface (part of JDK 6; separate jar available for JDK 5)

In addition to the parsing interfaces, the API provides an XSLT interface to provide data and structural transformations on an XML document.

DOM interface
DOM model parses an entire XML document and constructs a complete in-memory representation of the document. The created objects are from package e org.w3c.dom.

SAX interface
The SAX parser is called the SAXParser and is created by the javax.xml.parsers.SAXParserFactory. Unlike the DOM parser, the SAX parser does not create an in-memory representation of the XML document and so is faster and uses less memory. Instead, the SAX parser informs clients of the XML document structure by invoking callbacks, that is, by invoking methods on a org.xml.sax.helpers.DefaultHandler instance provided to the parser.

The DefaultHandler class implements these interfaces:
* ContentHandler
* DTDHandler
* EntityResolver
* ErrorHandler

StAX interface
StAX was designed as a median between the DOM and SAX interface. In its metaphor, the programmatic entry point is a cursor that represents a point within the document. The application moves the cursor forward - 'pulling' the information from the parser as it needs.

XSLT interface
It allows applying transformations (XSL transformations) to XML files

No comments:

Post a Comment