Sometimes there is a need to ignore comment node in source XML file, while producing DOM-document. This allows to avoid extra checking of node types while browsing DOM-tree. In order to ignore comments a corresponding property of DocumentBuilderFactory object should be set to true. The following sample shows it:

   // create new factory is ordinary way:
  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

  // this will make the parsers produced by this factory will
  // ignore comments; by default comment-nodes are processed to DOM-tree: