Title: XML is valid BEFORE but invalid AFTER writing file.

Hi,

I have the following problem writing XML with special characters into a file...

I create the following Document structure:
<Person>
  <Id>7601000237200</Id>
  <Name>Baldinger</Name>
  <FirstName>René</FirstName>
  <ZipCode>8400</ZipCode>
</Person>

Using the MSV validator, the Document Structure seems to be valid according to the xsd.
But then I write the XML content to a file, with the following code:

FileWriter fileWriter = new FileWriter( path );
XMLWriter writer = new XMLWriter( fileWriter );
OutputFormat format = OutputFormat.createPrettyPrint();
writer = new XMLWriter( fileWriter, format );
writer.write( Document );
writer.close();

When I re-read this file from file system and validate again, it is invalid, giving me the following error:
<<Character conversion error: "Malformed UTF-8 char -- is an XML encoding declaration missing?" (line number may be too low)>>

If I write the file using the "UTF-16", the validator gives me the following error:
<<Character conversion error: "Missing byte-order mark" (line number may be too low)>>

When I write the file using encoding "windows-1252", there's no problem at all.

A bug?

Any suggestions? I'd like to use UTF-8!

Thanks in advance
Wonne Keysers

Reply via email to