Like what you read? Share for your friends!

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
Content Is Not Allowed In Prolog


Prolog error is also shown when yhe XML header do not have a beginning tag "<" before the Pseudo Attribute, first question 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.

Online Syntax Error Parsing XML Validator Tool can be used to check the parsing errors and find invisible characters.

To Solve this Prolog error;

Copy either of the below code and replace it with the existing XML header;

<?xml version="1.0" encoding="UTF-16" standalone="no"?>

or

<?xml version="1.0" encoding="UTF-8" ?>


Byte Order Markers

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
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: Content Is Not Allowed In Prolog
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. 


Comments || >

Subscribe via Email

Don't Miss Any Updates, Stay Connected!.

We respect your privacy and will never share your email address with any person or organisation.