0

I had this exception

org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 39; Content is not allowed in prolog.
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at jlibs.xml.sax.dog.XMLDog.sniff(XMLDog.java:188)

when using XMLDog sniff() method.

My Java code is

String xml = "..."
XPathResults results = xmlDog.sniff(new InputSource(new StringInputStream(xml)));

as you can see I have my XML in String, so there is no problem with UTF-8 BOF, also I'm sure that there are no whitespaces in xml string...

Betlista
  • 10,327
  • 13
  • 69
  • 110
  • Probably there is a ByteStream somewhere in there and you are getting a different character encoding when the string is decoded and when the bytestream is later re-encoded. – clacke Mar 31 '14 at 12:13
  • Correction: an InputStream *is* a stream of bytes, so there could definitely be encoding issues. – clacke Mar 31 '14 at 12:17
  • See also http://stackoverflow.com/questions/5138696/org-xml-sax-saxparseexception-content-is-not-allowed-in-prolog – Raedwald Jul 18 '14 at 09:29

1 Answers1

0

The reason I found later was, that I used StringInputStream class and didn't realize, that it is org.hsqldb.lib.StringInputStream.StringInputStream(String).

When I replaced this one with

  • java.io.StringBufferInputStream.StringBufferInputStream(String) // deprecated
  • or java.io.StringReader.StringReader(String) // sniff accepts reader too
  • or java.io.ByteArrayInputStream.ByteArrayInputStream(byte[])

...it worked. I didn't investigate why the previous one from hsqldb package is bad in this case...

Betlista
  • 10,327
  • 13
  • 69
  • 110