"Content is not allowed in prolog" for XML in Eclipse

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.

6 thoughts on “"Content is not allowed in prolog" for XML in Eclipse

  1. 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

  2. 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?

Leave a Reply