Java API for XML Processing

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 two basic parsing interfaces are:

In addition to the parsing interfaces, the API provides an XSLT interface to provide data and structural transformations on an XML document. The J2SE 1.4 JDK is the first version of a JDK comes with an implementation of JAXP 1.1.

Contents

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 Document Object Model(DOM) Level 2 Core Specification (http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113).

The DOM parser is called a DocumentBuilder, as it builds an in-memory Document representation. The javax.xml.parsers.DocumentBuilder is created by the javax.xml.parsers.DocumentBuilderFactory. The DocumentBuilder creates an org.w3c.dom.Document instance, which is a tree structure containing nodes in the XML Document. Each tree node in the structure implements the 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 package org.w3c.dom for a complete list of node types.

SAX interface

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

The DefaultHandler class is found in the org.xml.sax.helpers package. It implements the ContentHandler, the ErrorHandler, the DTDHandler, and the EntityResolver interfaces. Most clients will be interested in methods defined in the ContentHandler interface.

The ContentHandler methods implemented by the DefaultHandler 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.

XSLT interface

The XML Stylesheet Language for Transformations, or XSLT, allows for conversion of an XML document into other forms of data.

Hello

Additional Resources

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools