[jdom-interest] non-ascii characters in xml document

Dave Neuendorf dneuendorf at earthlink.net
Thu Nov 29 10:38:38 PST 2001


I'm working on an application, in which the user is allowed to paste
text into a JTextArea. The text can include "curly" single and double
quotes, and presumably other non-ascii characters. When the text is
written to an xml file from a jdom Document, each such character is
replaced in the file with some other non-ascii character. I tried
changing the encoding from the default UTF-8 to ISO-8859-1, but the
result is that now the replacement character is always a question mark.
Does anyone know how to safely persist characters such as these
quotation marks? My xml file save code is shown below:

                XMLOutputter outputter = new XMLOutputter();
                outputter.setIndent( "  " );
                outputter.setNewlines( true );
                outputter.setEncoding( "ISO-8859-1" );
                try
                {
                    ByteArrayOutputStream bytesOut = new
ByteArrayOutputStream();
                    outputter.output( doc, bytesOut );
                    GZIPOutputStream out = new GZIPOutputStream( new
FileOutputStream( "default.xmlz" ) );
                    bytesOut.writeTo( out );
                    out.close();
                }
                catch ( IOException e )
                {
                    String message = getResources().getString(
"errorMessages.noSaveData" );
                    JOptionPane.showMessageDialog( HierarchicalPIM.this,
message );
                }

I'll appreciate any help.

Dave Neuendorf





More information about the jdom-interest mailing list