Title: RE: [dom4j-user] XML is valid BEFORE but invalid AFTER writing file.

Hello again,

I managed to solve the problem myself... :-)

Instead of using a java.io.FileWriter, I took the java.io.FileOutputStream and it works. It seems the provided OutputFormat.getEncoding() is not used when using the FileWriter...

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

Regards,
Wonne

-----Original Message-----
From: Keysers, Wonne
To: '[EMAIL PROTECTED] '
Cc: Keunen, Patrick
Sent: 1/20/2003 11:59 AM
Subject: [dom4j-user] XML is valid BEFORE but invalid AFTER writing file.
Importance: High

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