0

I am trying to run my XSLT project. But I am getting the following error,

lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.

I tried this removing <?xml version="1.0" encoding="UTF-8"?> and comment that is just after <?xml version="1.0" encoding="UTF-8"?> from each and every file. But It also shows the same error. How can I fix this? I am using XSLT 2.0

user_v12
  • 559
  • 5
  • 15
  • Regarding your edit, why did you remove important information from your question, including that the error message originated from Saxon? – kjhughes May 21 '20 at 18:10
  • @kjhughes Actually I think my file content is not important here. If you ask me to add them again I can add them. I have validated my files and They all are well formated. – user_v12 May 21 '20 at 18:12
  • Your file content is certainly important, but the problem may very well reside in different files that you've not included -- be sure to check (mostly [here](https://stackoverflow.com/a/19898942/290085) but perhaps [here](https://stackoverflow.com/q/51500738/290085) as well) not only the XSLT, but the XML (and any XSDs) as well. (And regardless you shouldn't have edited the error message unless you weren't in fact using Saxon.) – kjhughes May 21 '20 at 18:26

1 Answers1

1

First step is to find out which XML file is causing the trouble. Saxon would output the file name if it knew it; the fact that you aren't seeing a file name might mean that the input is an anonymous stream rather than a file. Look for cases where you create a Source object from a FileInputStream without supplying a system Id.

Getting a stack trace for the exception will help you to identify where in your code you need to look.

The message from Xerces typically comes when the first character of a file that's submitted for XML parsing isn't "<". But experience shows that this can be a symptom with a wide variety of root causes. Removing the XML declaration from a file is very unlikely to help (but removing a blank line before the XML declaration most definitely would).

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • Still no progress. – user_v12 May 21 '20 at 17:23
  • @user_v12: Check each of your XML/XSLT/XSD files against the possibilities listed [here](https://stackoverflow.com/a/19898942/290085) (and do not delete and repost your question again!). – kjhughes May 21 '20 at 18:02
  • Have you got a stack trace for the exception? – Michael Kay May 21 '20 at 20:18
  • It's also possible that the error is not in any file, but in some in-memory XML that's generated and consumed within your application. You've told us so little about the application that we really can't rule anything like this out. – Michael Kay May 21 '20 at 20:20