Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

[Fatal Error] :1:1: Content is not allowed in prolog.

800380Jan 23 2009 — edited Nov 20 2009
I'm trying to compare an XML file to an XSLT generated file from that XML file, and when I run the the class as a JUnit Test, I get the following:

[Fatal Error] :1:1: Content is not allowed in prolog.


org.xml.sax.SAXParseException: Content is not allowed in prolog.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at org.custommonkey.xmlunit.XMLUnit.buildDocument(XMLUnit.java:352)
at org.custommonkey.xmlunit.XMLUnit.buildDocument(XMLUnit.java:339)
at org.custommonkey.xmlunit.XMLUnit.buildControlDocument(XMLUnit.java:283)
at org.custommonkey.xmlunit.Diff.<init>(Diff.java:116)
at org.custommonkey.xmlunit.examples.MyXMLTestCase.testXSLTransformation(MyXMLTestCase.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:230)
at junit.framework.TestSuite.run(TestSuite.java:225)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

Any ideas?

Comments

807580
What does your expected document look like? The one you're applying the transform to?
800380
It is an XML file. And, here comparing an XML to an XSLT file.
807580
Abder-Rahman wrote:
It is an XML file. And, here comparing an XML to an XSLT file.
So what does the file look like? And why compare XML to an XSLT transform?
807580
In my experience, "Content is not allowed in prolog" usually means your XML file is stored in the UTF-8 encoding with a BOM. Java's UTF-8 Charset doesn't recognize the UTF-8 BOM; it decodes it and passes it along like any other character, then the XML parser chokes on it.

To get rid of the BOM you can open the XML file in a text editor and (depending on the editor) either (1) save the file as UTF-8 without BOM, or (2) switch to hexadecimal and delete the first three bytes (EF, BB, BF).
807580
[http://forums.sun.com/thread.jspa?threadID=465472]
796440
uncle_alice wrote:
In my experience, "Content is not allowed in prolog" usually means your XML file is stored in the UTF-8 encoding with a BOM.
I've even seen it for something as simple as a trailing space in the prolog, e.g.
|<?xml version="1.0"?> |
(where the pipes are just there to show the trailing space, obviously)
807580
I learned a lot from this article. thanks for all who contributed to this post:

here is what I do to get my parser to behave... i strip off the first 3 characters:

getXMLContents(file2).substring(3)

More info here:
[http://www.personalmicrocosms.com/pages/blog.aspx?b=60|http://www.personalmicrocosms.com/pages/blog.aspx?b=60]
1 - 7
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Dec 18 2009
Added on Jan 23 2009
7 comments
4,965 views