org.xml.sax.SAXParseException XML declaration may only begin entities

I get this error:

org.xml.sax.SAXParseException: XML declaration may only begin entities.

From this line:
document = factory.newDocumentBuilder().parse(new File(arg));

Where arg = "C:\TransferComm\32\inbox\grantoverby31.xml"

This worked at one point and is now broken. I'm clueless.

Please help quickly. This is an issue on a production server.
LVL 3
modsiwAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
Have you made any changes to the xml file?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
Make sure you have no comments before the prologue
CEHJCommented:
And make sure you haven't opened it in an editor that has left binary characters at the beginning of the file or any whitespace
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Mick BarryJava DeveloperCommented:
If you have made changes to the xml, then first step would be to roll back the changes on your prod server.
Then do a diff on the working file against the latest, that will show exactly what is causing the problem.
modsiwAuthor Commented:
Someone made changes to the XML writer with out my knowledge (legacy system). The first character of the documents was a CR, which wasn't being displayed in my editor.

Thanks for the replies guys.
CEHJCommented:
>>The first character of the documents was a CR, which wasn't being displayed in my editor.

( As i mentioned at http:Q_21679737.html#15581050 )
modsiwAuthor Commented:
True enough.

The reason I accepted Object's answer was because it lead to the correct answer before you posted. I was a bit slow with my reply and awarding points because I was busy dealing with other things.

You were both right. Many thanks for your reply CEHJ and all of the other help you've left in the PAQs. Objects simply read the question and replied with a suitable solution first :(
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.