Java API for XML Processing

The Java API for XML Processing, or JAXP (pronounced "jaks-p"), 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 (added in 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. JAXP was developed under the Java Community Process as JSR 5 (JAXP 1.0) and JSR 63 (JAXP 1.1 and 1.2). J2SE 1.4 is the first version of Java that comes with an implementation of JAXP. JAXP version 1.4.2 was released on May 30, 2007. JAXP 1.3 was [https://jaxp.dev.java.net/1.3/EndofLife.html end-of-lifed] on February 12, 2008.

DOM interface

The DOM interface is perhaps the easiest to understand. It parses an entire XML document and constructs a complete in-memory representation of the document using the classes modeling the concepts found in the [http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113 Document Object Model(DOM) Level 2 Core Specification] .

The DOM parser is called a DocumentBuilder, as it builds an in-memory Document representation. The Javadoc:SE|package=javax.xml.parsers|javax/xml/parsers|DocumentBuilder is created by the Javadoc:SE|package=javax.xml.parsers|javax/xml/parsers|DocumentBuilderFactory. The DocumentBuilder creates an Javadoc:SE|package=org.w3c.dom|org/w3c/dom|Document instance, which is a tree structure containing nodes in the XML Document. Each tree node in the structure implements the Javadoc:SE|package=org.w3c.dom|org/w3c/dom|Node interface. There are many different types of tree nodes, representing the type of data found in an XML document. The most important node types are:
* element nodes which may have attributes
* text nodes representing the text found between the start and end tags of a document element.

Refer to the Javadoc documentation of the Java package Javadoc:SE|package=org.w3c.dom|org/w3c/dom for a complete list of node types.

SAX interface

The SAX parser is called the Javadoc:SE|javax/xml/parsers|SAXParser and is created by the Javadoc:SE|package=javax.xml.parsers|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 Javadoc:SE|package=org.xml.sax.helpers|org/xml/sax/helpers|DefaultHandler instance provided to the parser.

The DefaultHandler class implements the Javadoc:SE|org/xml/sax|ContentHandler, the Javadoc:SE|org/xml/sax|ErrorHandler, the Javadoc:SE|org/xml/sax|DTDHandler, and the Javadoc:SE|org/xml/sax|EntityResolver interfaces. Most clients will be interested in methods defined in the ContentHandler interface which are called when the SAX parser encounters the corresponding elements in the XML document. The most important methods in this interface are:
* startDocument() and endDocument() methods that are called at the start and end of an XML document.
* startElement() and endElement() methods that are called at the start and end of a document element.
* characters() method that is called with the text data contents contained between the start and end tags of an XML document element.

Clients provide a subclass of the DefaultHandler that overrides these methods and processes the data. This may involve storing the data into a database or writing it out to a stream.

During parsing, the parser may need to access external documents. It is possible to store a local cache for frequently-used documents using an XML Catalog.

XSLT interface

The XML Stylesheet Language for Transformations, or XSLT, allows for conversion of an XML document into other forms of data. JAXP provides interfaces in package javax.xml.transform allowing applications to invoke an XSLT transformation. This interface was originally called TrAX (Transformation API for XML), and was developed by an informal collaboration between the developers of a number of Java XSLT processors.

Main features of the interface are:

* a factory class allowing the application to select dynamically which XSLT processor it wishes to use

* methods on the factory class to create a Templates object, representing the compiled form of a stylesheet. This is a thread-safe object that can be used repeatedly, in series or in parallel, to apply the same stylesheet to multiple source documents (or to the same source document with different parameters)

* a method on the Templates object to create a Transformer, representing the executable form of a stylesheet. This cannot be shared across threads, though it is serially reusable. The Transformer provides methods to set stylesheet parameters and serialization options (for example, whether output should be indented), and a method to actually run the transformation.

Two abstract interfaces Source and Result are defined to represent the input and output of the transformation. This is a somewhat unconventional use of Java interfaces, since there is no expectation that a processor will accept any class that implements the interface - each processor can choose which kinds of Source or Result it is prepared to handle. In practice all JAXP processors support the three standard kinds of Source (DOMSource, SAXSource, StreamSource) and the three standard kinds of Result (DOMResult, SAXResult, StreamResult) and possibly other implementations of their own.

External links

* See [http://java.sun.com/webservices/jaxp/ Sun's JAXP product description]
* [http://www.jcp.org/en/jsr/detail?id=63 JSR 63] (JAXP 1.1 and 1.2)
* [http://www.jcp.org/en/jsr/detail?id=5 JSR 5] (JAXP 1.0)
* See [http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113 Document Object Model(DOM) Level 2 Core Specification]
* Sample programs using DOM and SAX parser [http://totheriver.com/learn/xml/xmltutorial.html Tutorial: XML with Xerces for Java]
* [http://www.ibm.com/developerworks/xml/library/x-xjavaforum4.html Sun's Java and XML APIs: Helping or hurting?]


Wikimedia Foundation. 2010.

Look at other dictionaries:

  • Java API For XML Processing — (JAXP) est l interface de programmation Java de Sun permettant la création, la manipulation et le traitement de fichiers XML à bas niveau. Cette interface permet d analyser les fichiers XML selon les normes DOM ou SAX, et de les transformer à l… …   Wikipédia en Français

  • Java API for XML Processing — (JAXP) est l interface de programmation Java de Sun permettant la création, la manipulation et le traitement de fichiers XML à bas niveau. Cette interface permet d analyser les fichiers XML selon les normes DOM ou SAX, et de les transformer à l… …   Wikipédia en Français

  • Java API for XML Processing — Das Java API for XML Processing, oder JAXP, ist eines der Java XML APIs. Es handelt sich um ein leichtgewichtiges standardisiertes API zum Validieren, Parsen, Generieren und Transformieren von XML Dokumenten. Die jeweilige (nicht standardisierte) …   Deutsch Wikipedia

  • Streaming API for XML — (StAX) ist ein Application Programming Interface (API), um XML Dateien aus Java zu verarbeiten. Die Referenzimplementierung ist als freie Software unter den Bedingungen der Apache Lizenz verfügbar. Inhaltsverzeichnis 1 Technik 2 Ursprünge 3 …   Deutsch Wikipedia

  • Simple api for xml — Pour les articles homonymes, voir SAX. Simple API for XML ou SAX est une interface de programmation pour de nombreux langages permettant de lire et de traiter des documents XML. L’API SAX est originellement spécifique au langage de programmation… …   Wikipédia en Français

  • Simple API for XML — Pour les articles homonymes, voir SAX. Simple API for XML ou SAX est une interface de programmation pour de nombreux langages permettant de lire et de traiter des documents XML. L’API SAX est originellement spécifique au langage de programmation… …   Wikipédia en Français

  • Java Specification Request — Java Specification Requests Java Specification Requests (JSR) est un système normalisé ayant pour but de faire évoluer la plateforme Java. Sommaire 1 Présentation 2 Implémentation 3 Interopérabilité informatique …   Wikipédia en Français

  • Java Specification Requests — (JSR) est un système normalisé ayant pour but de faire évoluer la plateforme Java. Sommaire 1 Présentation 2 Implémentation 3 Liste des JSRs 4 Notes et …   Wikipédia en Français

  • Java 2 Enterprise Edition — Java Platform, Enterprise Edition, abgekürzt Java EE oder früher J2EE, ist die Spezifikation einer Softwarearchitektur für die transaktionsbasierte Ausführung von in Java programmierten Anwendungen und insbesondere Web Anwendungen. Sie ist eine… …   Deutsch Wikipedia

  • Java 2 Platform Enterprise Edition — Java Platform, Enterprise Edition, abgekürzt Java EE oder früher J2EE, ist die Spezifikation einer Softwarearchitektur für die transaktionsbasierte Ausführung von in Java programmierten Anwendungen und insbesondere Web Anwendungen. Sie ist eine… …   Deutsch Wikipedia


Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”

We are using cookies for the best presentation of our site. Continuing to use this site, you agree with this.