DomClassInfo.java - DOM Implementation Class

Q

How to verify the DOM (Document Object Model) implementation class information?

✍: FYIcenter

A

If you want to verify the DOM (Document Object Model) implementation class information, you can try the following example program:

// Copyright (c) 2017 FYIcenter.com
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;

public class DomClassInfo {
   public static void main(String[] args) throws Exception {
      DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
      DocumentBuilder b = f.newDocumentBuilder();
      Document d = b.newDocument();
      
      Element e = d.createElement("Msg"); 
      Text t = d.createTextNode("Hello World!");
      e.appendChild(t);
      d.appendChild(e);
      
      System.out.println("DOM class info:");
      System.out.println("   Factory: "+f.getClass().getName());
      System.out.println("   Builder: "+b.getClass().getName());
      System.out.println("   Document: "+d.getClass().getName());
      System.out.println("   Element: "+e.getClass().getName());
      System.out.println("   TextNode: "+t.getClass().getName());
   }
}

Compile and test it:

>\fyicenter\jdk-1.8.0\bin\javac DomClassInfo.java

>\fyicenter\jdk-1.8.0\bin\java DomClassInfo
DOM class info:
   Factory: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
   Builder: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl
   Document: com.sun.org.apache.xerces.internal.dom.DocumentImpl
   Element: com.sun.org.apache.xerces.internal.dom.ElementImpl
   TextNode: com.sun.org.apache.xerces.internal.dom.TextImpl

The output tells you that the default implementation of DOM in Java SE 8 JDK is the Apache Xerces package.

 

Using XML DOM API with Apache Xerces

⇒⇒FAQ for Apache Xerces XML Parser

2017-09-08, 263👍, 0💬