Reputation: 970
This question is a follow-up of this question:
Error: The processing instruction target matching "[xX][mM][lL]" is not allowed
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.
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.
Is there a solution to ignore the second XML declaration without editing the file manually or whatsoever?
I am using scala library "scala.xml".
Upvotes: 2
Views: 5213
Reputation: 163458
Your input is not well-formed XML so you cannot process it successfully using an XML parser. Best to avoid generating it in the first place; if you can't do that, you'll have to repair the file using non-XML tools.
Upvotes: 2