By default, DOM reads entire data from source XML file. Besides elements, attributes and comments it also processed character data like line-feeds or new-line symbols. Sometimes such approach is inacceptable. In order to ignore whitespaces around DOM-nodes DOM-factory should be configured in the following way:

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

  // this will make the parsers created by this  factory must eliminate
  // whitespace in element content:
  factory.setIgnoringElementContentWhitespace(true);