XDK: DocumentBuilderFactory does not Honor setIgnoringComments()

(Doc ID 1379629.1)

Last updated on FEBRUARY 08, 2017

Applies to:

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

Symptoms

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);
      factory.setIgnoringComments(true);
      DocumentBuilder builder = factory.newDocumentBuilder();
      System.out.println("Builder=" + builder);
      InputSource input = new InputSource(
                                new StringReader("<test><!-- comment --></test>"));
      Document document = builder.parse(input);
      dump(document.getChildNodes());
    }

  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());
      dump(item.getChildNodes());
    }
  }
}



2. Run the code using:

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


Sample Output:

Factory=oracle.xml.jaxp.JXDocumentBuilderFactory@35d9dc39
Builder=oracle.xml.jaxp.JXDocumentBuilder@2a0ecd7e
- Item:test=null
- Item:#comment= comment

Cause

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