XDK: DocumentBuilderFactory does not Honor setIgnoringComments()

(Doc ID 1379629.1)

Last updated on FEBRUARY 08, 2017

Applies to:

Oracle XML Developers Kit - Version and later
Information in this document applies to any platform.
***Checked for relevance on 07-Jun-2013***


The DocumentBuilderFactory created by JXDocumentBuilderFactory does not honor the setting setIgnoringComments(true). The code below will print a comment node if run with xmlparserv2.jar in the classpath.

Example code - XMLParserTest.java:

1. Compile the code using:

javac $ javac XMLParserTest.java

import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;

public class XMLParserTest {

  public static void main(String[] args)
    throws ParserConfigurationException, SAXException, IOException {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      System.out.println("Factory=" + factory);
      DocumentBuilder builder = factory.newDocumentBuilder();
      System.out.println("Builder=" + builder);
      InputSource input = new InputSource(
                                new StringReader("<test><!-- comment --></test>"));
      Document document = builder.parse(input);

  private static void dump(NodeList nodeList) {
    for (int i = 0; i < nodeList.getLength(); i++) {
      Node item = nodeList.item(i);
      System.out.println("- Item:" + item.getNodeName() + "=" + item.getNodeValue());

2. Run the code using:

java -cp .:$ORACLE_HOME/xdk/lib/xmlparserv2.jar XMLParserTest

Sample Output:

- Item:test=null
- Item:#comment= comment


Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms