Using DOM Implementation Provided in JDK

This section provides a tutorial example on how to use the DOM interface included in JDK, which actually uses DOM implementation provided in the org.apache.crimson package.

Here is a program to show how different packages are used together to parse an XML file into a DOM document object:

 - Copyright (c) 2002-2018 All Rights Reserved.
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
class DOMParser {
   public static void main(String[] args) {
      try {
         File x = new File(args[0]);
         DocumentBuilderFactory f
            = DocumentBuilderFactory.newInstance();
         DocumentBuilder b = f.newDocumentBuilder();
         Document d = b.parse(x);
         DOMImplementation i = d.getImplementation();
      } catch (ParserConfigurationException e) {
      } catch (SAXException e) {
      } catch (IOException e) {

If you compile and run this sample program with JDK (Java Development Kit), you will get:

herong> java DOMParser hello.xml
[#document: null]

Note that:

Table of Contents

 About This Book

 Introduction of XML (eXtensible Markup Language)

 XML File Syntax

 XML File Browsers

 XML-JSON Document Conversion

DOM (Document Object Model) Programming Interface

 What Is DOM (Document Object Model)

Using DOM Implementation Provided in JDK

 DOM Specifications and DOM Node Interface - DOM Interface Java Example

 XML DOM Node Tree Example

 Building a New DOM Document Object

 Converting DOM Document Objects to XML Files

 SAX (Simple API for XML) Programming Interface

 DTD (Document Type Definition) Introduction

 Syntaxes of DTD Statements

 Validating an XML Document against the Specified DTD Document Type

 XSD (XML Schema Definition) Introduction

 Syntaxes of XSD Statements

 Validating XML Documents Against Specified XML Schemas

 XSL (Extensible Stylesheet Language) Introduction

 Java Implementation of XSLT

 XSLT (XSL Transformations) Introduction

 XPath (XML Path) Language

 XSLT Elements as Programming Statements

 Control and Generate XML Element in the Result

 PHP Extensions for XML Manipulation

 Processing XML with Python Scripts

 XML Notepad - XML Editor

 XML Tools Plugin for Notepad++

 XML Plugin Packages for Atom Editor

 XML 1.1 Changes and Parsing Examples

 Archived Tutorials


 Full Version in PDF/EPUB