There is one other case where you will get
this error. That’s where you include a prolog that declared the
data as UTF-16, but the actual data written was NOT truly UTF-16. Here is
a snippet I use to write data out: new
File(filePath).delete(); //
open file FileOutputStream
os = new FileOutputStream(new File(filePath)); //
write content String
strXML = getXML(doc, bIndent, strEncoding, bOmitXMLDeclaration); os.write(strXML.getBytes(strEncoding)); //
close file os.flush(); os.close(); The string strXML is stored in internal
Java string format, which is not exactly UTF-16. Most mechanisms to write
string data to a file result in the data being written using the current
code-page, which is likely neither UTF-8 nor any variation of UTF-16.
(You can use the old DOS DEBUG command to see if you actually have 16-byte
encoding or not.) Writing a bytestream that has been selected in the
appropriate format seems to solve the problem. You will have to select
either Little Endian or Big Endian UTF-16 variations (“UTF-16LE” or
“UTF-16BE” as I recall it) for strEncoding. I can’t
remember if this generates the appropriate byte order mark (I believe it does),
but most parsers will check the first several bytes in the absence of a BOM,
and if they see 0, ‘<’ or ‘<’ 0, they will figure
it out for you. However, if they see an encoding in the prolog that doesn’t
match the actual file, the parser will then assumed that what they thought was
a prolog was actually bogus leading bytes, and hence the message you are
getting. In short, there’s more than one way
to get this error message. From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] [Fatal
Error] output.xml:1:40: Content is not allowed in prolog. |
- Reading UTF-16: Content is not allowed in prolog Jones, David [deljones]
- Re: Reading UTF-16: Content is not allowed in... keshlam
- Re: Reading UTF-16: Content is not allowed in... Michael Glavassevich
- RE: Reading UTF-16: Content is not allowed in... Robert Houben
- RE: Reading UTF-16: Content is not allowe... Jones, David [deljones]