XML problem with Java

Status
You're currently viewing only evil-scientist's posts. Click here to go back to viewing the entire thread.
Not open for further replies.
you need to specify the encoding when writing out the stream to a file using OutputStreamWriter(OutputStream out, String enc)
Then you need to make sure you set the XML to have the same encoding.

something like (might not compile but you'll get the idea)

Code:
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root></root>";
FileOutputSteam fileOut = new FileOutputStream("fileName.xml");
OutputStreamWriter writer = new OutputStreamWriter(fileOut, "UTF-8");
writer.write(xml);
writer.close;

you can obviously wrapp in a buffered writer etc and will need to do the same but opposite InputStreamReader methods when reading the file. Java will use the default platform encoding when writing/reading characters from files which is causing the troubles since you XML has characters that aren't allowed.

On the other hand... check to make sure you are using the latest XML parsers etc. I spent a whole day trying to track down a similar problem before i realized the IBM jvm comes with a really old xerces.jar in the lib/ext dir.
 
Status
You're currently viewing only evil-scientist's posts. Click here to go back to viewing the entire thread.
Not open for further replies.