Java parsing XML document gives "Content not allowed in prolog." error [duplicate] Java parsing XML document gives "Content not allowed in prolog." error [duplicate] xml xml

Java parsing XML document gives "Content not allowed in prolog." error [duplicate]


Please check the xml file whether it has any junk character like this �.If exists,please use the following syntax to remove that.

String XString = writer.toString();XString = XString.replaceAll("[^\\x20-\\x7e]", "");


I think this is also a solution of this problem.

Change your document type from 'Encode in UTF-8' To 'Encode in UTF-8 without BOM'

I got resolved my problem by doing same changes.


Make sure there's no hidden whitespace at the start of your XML file. Also maybe include encoding="UTF-8" (or 16? No clue) in the node.