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...
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)
// deprecatedjava.io.StringReader.StringReader(String)
// sniff accepts reader toojava.io.ByteArrayInputStream.ByteArrayInputStream(byte[])
...it worked. I didn't investigate why the previous one from hsqldb package is bad in this case...