[jdom-interest] Question regarding encoding

Sinkinson,Andrew [NCR] Andrew.Sinkinson at ec.gc.ca
Thu Oct 7 12:13:43 PDT 2004


That Fixed it!  Thanks for the help.

-----Original Message-----
From: Elliotte Harold [mailto:elharo at metalab.unc.edu] 
Sent: October 7, 2004 3:03 PM
To: Sinkinson,Andrew [NCR]
Cc: jdom-interest at jdom.org
Subject: Re: [jdom-interest] Question regarding encoding


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%3Dno
sim



More information about the jdom-interest mailing list