Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal Error :1:1: Content is not allowed in prolog

Tags:

java

xml

I'm using Java and i'm trying to get XML document from some http link. Code I'm using is:

URL url = new URL(link);  HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); Document doc = null;  CountInputStream in = new CountInputStream(url.openStream()); doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in); 

Don't pay attention at CountInputStream, it's some special class acting like regular input stream.

Using the code above, I sometimes got error Fatal Error :1:1: Content is not allowed in prolog. I assume that is has something to do with bad format of xml, but I have no idea how to fix it.

like image 919
guest86 Avatar asked Jul 20 '12 10:07

guest86


People also ask

What does it mean content is not allowed in prolog?

Problem: You received the error message, “Content is not allowed in prolog.” The result of this error is that one or more files will not process in eFORMz. Solution: You must remove the content from the prolog.

How do you fix an org XML SAX Saxparseexception?

Fix: Remove StringReader() : Document doc = dBuilder. parse(new InputSource("file. xml"));


1 Answers

I'm turning my comment to an answer, so it can be accepted and this question no longer remains unanswered.

The most likely cause of this is a malformed response, which includes characters before the initial <?xml …>. So please have a look at the document as transferred over HTTP, and fix this on the server side.

like image 173
MvG Avatar answered Sep 20 '22 12:09

MvG