title: Problems parsing XML in Java
body: <p>I got some trouble parsing an XML document. For some reason, there are text nodes where I would not expect them to be and therefore my test turns red. The XML file looks like this:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;RootNode&gt;
    &lt;PR1&gt;PR1&lt;/PR1&gt;
    &lt;ROL&gt;one&lt;/ROL&gt;
    &lt;ROL&gt;two&lt;/ROL&gt;
    &lt;DG1&gt;DG1&lt;/DG1&gt;
    &lt;ROL&gt;three&lt;/ROL&gt;
    &lt;ZBK&gt;ZBK&lt;/ZBK&gt;
    &lt;ROL&gt;four&lt;/ROL&gt;
  &lt;/RootNode&gt;
  </code></pre>
  
  <p>Now I have this snippet of code which can reproduce the error:</p>
  
  <pre><code>DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  DocumentBuilder builder = factory.newDocumentBuilder();
  Document doc = builder.parse(TestHL7Helper.class.getResourceAsStream("TestHL7HelperInput.xml"));
  Node root = doc.getFirstChild();
  Node pr1 = root.getFirstChild();
  </code></pre>
  
  <p>Inspecting the root variable yields <code>[RootNode: null]</code> which seems to be right, but then it somehow goes all wrong. The <code>pr1</code> variable turns out to be a text node <code>[#text:\n  ]</code> - but why does the parser think that the new line and the spaces are a text node? Shouldn't that be ignored? I tried changing the encoding but that did not help either. Any ideas on that?</p>
  
  <p>If I remove all new lines and space and have my XML document in just one line it all works fine...</p>