Solved Java XML Parsing Error : Content is not allowed in prolog
Content Is Not Allowed In Prolog is an error when the documents contains invisible characters or characters before the XML header.
No Beginning Tag:Content Is Not Allowed In Prolog
Content Is Not Allowed In Prolog
Prolog error is also shown when yhe XML header do not have a beginning tag “<” before thePseudo Attribute, firstquestion mark in the XML header as shown in the image. If the document in not proper UTF and there are invisible characters between the XML header, a prolog error can be shown.
Byte order markers could be in the buffer. Before passing the buffer to the Parser do this.
String xml = “<?xml …”; xml = xml.trim().replaceFirst(“^([\W]+)<“,”<“);
Clearing the white spaces between characters also helps in sorting out the issue. If the XML header has white space before it, you may encounter another error:The processing instruction target matching “[xX][mM][lL]” is not allowed as shown in the below image.
The processing instruction target matching “[xX][mM][lL]” is not allowed
Characters Before XML header:Content Is Not Allowed In Prolog
If there are visible or invisible characters before the XML header, the error Content Is Not Allowed In Prolog will pop up. It
Characters Before XML header
As shown in the image, a character “x” was put before XML header, and error was shown. Even if there an extra small dot “.” in the beginning of XML element, the error will pop up.
Use Notepad++ to copy and paste all the codes and display all the characters by selecting Encoding “UTF-8 without BOM”. Solution is to remove all the whites pace and characters before the XML header.