I can't properly encode my XML output file and would appreciate any help you could offer!

For example, if I do the following:

<<
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    FileOutputStream fos = new FileOutputStream("C:/test.xml");
    PrintStream xmlStream = new PrintStream(fos, false, "UTF-8");   
      
    XmlOptions printOptions = new XmlOptions();
    printOptions.setSavePrettyPrint();
    printOptions.setSavePrettyPrintIndent (2);
    printOptions.setUseDefaultNamespace();
    printOptions.setCharacterEncoding("UTF-8");

    paymentDoc.save(bos,printOptions);
    xmlStream.print(bos);   //xmlStream.print(bos.toString("UTF-8"));
    xmlStream.close();
>>

I receive a properly formatted file, with all of the data I require.  However, per textpad, the encoding is set to ANSI.  I've tried numerous combinations of writers and encoding and can't seem to get the output into UTF-8!  I'll be dealing with Japanese and Korean characters so it is a necessity.

The crazy part is that if I perform the following:

<<
ByteArrayOutputStream bos = new ByteArrayOutputStream();

FileOutputStream fos = new FileOutputStream("C:/test.xml");
PrintStream xmlStream = new PrintStream(fos, false, "UTF-8");   

bos.write("A?u$(He933u3'u(BaÌ3̇".getBytes("UTF-8"));
xmlStream.print(bos);
xmlStream.close();
>>

The resulting file is listed as properly encoded in UTF-8 format!?

I'm at my wits end.  I'm using the latest XmlBeans release as of today and JDK 1.4.2_12.  I set the documentProperties encoding to UTF-8 as well and it just doesn't want to play nice.

Help!

Thanks, Mike

Reply via email to