title: Error: The processing instruction target matching “[xX][mM][lL]” is not allowed
body: <p>This question is a follow-up of this question:</p>
  
  <p><a href="https://stackoverflow.com/questions/19889132/error-the-processing-instruction-target-matching-xxmmll-is-not-allowed">Error: The processing instruction target matching &quot;[xX][mM][lL]&quot; is not allowed</a></p>
  
  <p>As the answer in the question says, this error appears when an XML declaration is encountered anywhere other than at the top of an XML file.
  The file I am processing does have the XML declaration twice.</p>
  
  <p>The peculiar thing is, the error does not always appear. If it fails first time and I re-run the code, it passes. Sometimes, it fails 2-3 times and passes when I run it for the next time. In production environment, it has never failed, even though I am downloading the same file and using the same code.</p>
  
  <p>Is there a solution to ignore the second XML declaration without editing the file manually or whatsoever?</p>
  
  <p>I am using scala library "scala.xml".</p>