title: Remove doctype containing entity from xml using java
body: <p>I'm trying to process an xml, before that i need to remove the doctype and entity declaration from the input xml.</p>
  
  <p>I'm using the below code to remove the doctype and entity:</p>
  
  <pre><code>fileContent = fileContent.replaceAll("&lt;!ENTITY ((.|\n|\r)*?)\"&gt;", "");
  fileContent = fileContent.replaceAll("&lt;!DOCTYPE((.|\n|\r)*?)&gt;", "");
  </code></pre>
  
  <p>This removes the entity and then the doctype. 
  This works fine if the xml contains below doctype declarations in the xml:</p>
  
  <pre><code>&lt;!DOCTYPE ichicsr SYSTEM "http://www.w3.org/TR/html4/frameset.dtd"&gt;
  
  &lt;!DOCTYPE ichicsr SYSTEM "D:\UPGRADE\NTServices\Server\\Xml21.dtd"
  [&lt;!ENTITY % entitydoc SYSTEM "D:\UPGRADE\NTServices\Server\\latin-entities.dtd"&gt; %entitydoc;]&gt;
  </code></pre>
  
  <p>But if I have the doctype as given below, it doesn't work and the root tag in the xml get stripped off:</p>
  
  <pre><code>&lt;!DOCTYPE ichicsr SYSTEM "D:\UPGRADE\NTServices\Server\\Xml21.dtd" 
  [&lt;!ENTITY % entitydoc SYSTEM 'D:\UPGRADE\NTServices\Server\\Xml21.dtd'&gt;
  ]&gt; 
  </code></pre>
  
  <p>Please let me know if the regular expression I'm using is incorrect or any other action needs to be taken.</p>