Forum Stats

  • 3,741,231 Users
  • 2,248,397 Discussions
  • 7,861,693 Comments

Discussions

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

800380
800380 Member Posts: 94
edited Nov 20, 2009 2:12PM in Java Programming
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
    807580 Member Posts: 33,048
    What does your expected document look like? The one you're applying the transform to?
  • 800380
    800380 Member Posts: 94
    It is an XML file. And, here comparing an XML to an XSLT file.
  • 807580
    807580 Member Posts: 33,048
    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
    807580 Member Posts: 33,048
    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
    807580 Member Posts: 33,048
    [http://forums.sun.com/thread.jspa?threadID=465472]
  • 796440
    796440 Member Posts: 19,179
    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
    807580 Member Posts: 33,048
    edited Nov 20, 2009 2:12PM
    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]
This discussion has been closed.