my2cents

16. June, 2007

“Content is not allowed in prolog” for XML in Eclipse

Filed under: Java,Software Development — frightanic @ 23:19

This blog now resides at http://www.frightanic.com/. It will be discontinued here…

Sometimes life as a software developer is almost too painful for me to bear. It’s ok to debug a piece of code for hours or to rack one’s brains over a problem instead of getting a good night’s rest; that’s part of the deal. What I can’t stand is solving a problem after hours and realizing that I had been barking up the wrong tree all the time.

While working on my first Sun SPOT project (blog posts on that are ahead) with Eclipse, the ANT editor all of a sudden reported an error on an XML build file: “content is not allowed in prolog”. While I was vaguely familiar with the meaning of it I could not see what was wrong with the XML file. For hours I searched the Internet, played around with my Eclipse preferences, and studied the first few lines of my build file. I loaded the file into the XML editor to confirm that it was valid indeed. I also loaded it into XmlSpy to double check. I did the right thing but missed to draw the right conclusions. As an XML document the file was ok, but as an ANT file it obviously wasn’t.

It was only after too many hours that I started stripping down the file, removing everything that wasn’t absolutely necessary. The error disappeared. So, I started removing individual lines to find the hot spot. When I stumbled upon an ANT <import> tag it finally dawned on me: the error was absolutely correct, but it simply referred to a different file. It was the imported file that couldn’t be parsed.

Yes, lesson learned. Indeed. I’ll never make that mistake again.

Advertisements

9 Comments

  1. What was the error. A wrong char on prolog ?

    Comment by glb — 17. July, 2007 @ 16:00

  2. Good point, but I don’t remember that. However, once you find the file in question it should be pretty easy to turn it into a valid XML file.

    Comment by frightanic — 17. July, 2007 @ 16:11

  3. what is a valid file to import using ant?

    Comment by Neha — 3. August, 2007 @ 12:11

  4. damn! the file i was trying to import was not a valid ant build file, therefore the error

    anyway, for others who might hit upon the same problem, the imported file must also be a valid ant build file

    Comment by Neha — 3. August, 2007 @ 12:21

  5. Thanks for the tip, you have saved one developer from night sweat and headaches.

    Comment by Tinashe B Chipomho — 9. October, 2007 @ 05:43

  6. I had the same problem.

    The cause: I renamed the project source directory to PROJECTS from Projects (which is given in the build.xml)

    I tried to replace Projects with PROJECTS in the xml, it didn’t work

    One more thing: Can you tell me how you have done the spell check in this editor?

    Comment by Mini — 29. April, 2009 @ 08:47

  7. I had the same problem. Thanks for the post. As soon as I read it, my solution dawned on me. I was importing another ant file that contained tasks shared with other ant files. In my imported file, I had the xml tag, , defined in both files. I changed my import to a property and used the ant task to call the desired target in the “imported” ant file. Hope this help someone else out there. I spent way too much time figuring that one out.

    Comment by Victor — 14. July, 2009 @ 15:43

  8. Hello Victor, I’m interested by the solution you found.
    Could you post the way you named the property? And the way you call ant tasks from the imported Ant file?
    Because I try to import multiples build.xml dispatched in different sub-directories, and I would like to launch all “dist” target from the different imported build.xml files.

    Regards,

    Comment by dargogo — 12. March, 2010 @ 09:48

  9. Hi,

    My Name is manish , I got the same issue. To resolve this issue, I have to simply check that extra characters should not be present. lime – here – Was by mistake a copy paste thing and the moment I removed this the error gone.

    I guess this will help you guys

    Comment by MANISH — 14. October, 2010 @ 08:43


RSS feed for comments on this post.

Create a free website or blog at WordPress.com.

%d bloggers like this: