[jdom-interest] Question regarding encoding

Elliotte Harold elharo at metalab.unc.edu
Thu Oct 7 12:03:19 PDT 2004


Sinkinson,Andrew [NCR] wrote:

> 
>   Hi All,
> 
>   Why are my French apostrophe being converted to questions marks ?
>   If I have the following input Xml document:
> 
>   <?xml version="1.0" encoding="ISO-8859-1"?>
> <record>
>     <description>L’architecture de GI/TI </description>
> </record>
> 
>   Parse the document with jdom and write it to the file system with the 
> following format
>   Format format = 
> Format.getCompactFormat().setEncoding("ISO-8859-1");                    
>   XMLOutputter out = new XMLOutputter(format);
>   FileWriter f = new FileWriter(new File(filename));

FileWriter uses the default encoding of the local platform, which won't 
always be ISO 8859-1. Try using an OutputStreamWriter chained to a 
FileOutputStream instead, and explicitly specify ISO-8859-1 as the 
encoding of the OutputStreamWriter. (XOM doesn't allow using a Writer 
for serialization precisely to avoid this problem.)

-- 
Elliotte Rusty Harold  elharo at metalab.unc.edu
XML in a Nutshell 3rd Edition Just Published!
http://www.cafeconleche.org/books/xian3/
http://www.amazon.com/exec/obidos/ISBN%3D0596007647/cafeaulaitA/ref%3Dnosim


More information about the jdom-interest mailing list