title: Malformed xml after regex replacement
body: <p>I'm trying to parse an XML file with Java.
  Before I start parsing, I need to replace (encode) some text between the <code>&lt;code&gt;</code> and <code>&lt;/code&gt;</code> tags.</p>
  
  <p>Therefore I read the contents of the file into a String:</p>
  
  <pre><code>File xml = new File(this.xmlFileName);
  final BufferedReader reader = new BufferedReader(new FileReader(xml));
  final StringBuilder contents = new StringBuilder();
  while (reader.ready()) {
      contents.append(reader.readLine());
  }
  reader.close();
  final String stringContents = contents.toString();
  </code></pre>
  
  <p>After I readed the XML into the string, I encode the values using <code>Pattern</code> and <code>Matcher</code>:</p>
  
  <pre><code>StringBuffer sb = new StringBuffer();
  Pattern p = Pattern.compile("&lt;code&gt;(.*?)&lt;/code&gt;", Pattern.DOTALL);
  Matcher m = p.matcher(stringContents);
  while (m.find()) {
      //Encode text between &lt;code&gt; and &lt;/code&gt; tags
      String valueFromTags = m.group(1);
      byte[] decodedBytes = valueFromTags.getBytes();
      new Base64();
      String encodedBytes = Base64.encodeBase64String(decodedBytes);
      m.appendReplacement(sb, "&lt;code&gt;" + encodedBytes + "&lt;/code&gt;");
  }
  m.appendTail(sb);
  String result = sb.toString();
  </code></pre>
  
  <p>After the replacements are done, I try to read this <code>String</code> into the XML parser:</p>
  
  <pre><code>DocumentBuilderFactory dbFactory = DocumentBuilderFactory
          .newInstance();
  DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
  Document doc = dBuilder.parse(result);
  doc.getDocumentElement().normalize();
  </code></pre>
  
  <p>But then I get this error: <code>java.net.MalformedURLException: no protocol: &lt;root&gt; &lt;application&gt;       &lt;interface&gt;...</code></p>
  
  <p>As you can see, after I read the <code>File</code> into a <code>String</code>, for some reasons there are a lot of spaces added, where there were newlines or tabs in the original file. So I think that's the reason why I get this error. Is there any way I can solve this?</p>