There are 2 problems with this:

> to read:
> 
> SAXReader reader = new SAXReader();
>         Document document = reader.read(file);
>         return document;

First of all, you're currently using the default parser which does not seem 
to be able to handle UTF-8 correctly.

Use the 'javax.xml.parsers.SAXParserFactory' property to specify a better 
parser.

Use something like this to set the Xerces parser:
System.setProperty( "javax.xml.parsers.SAXParserFactory", 
                               "org.apache.xerces.jaxp.SAXParserFactoryImpl");

> to write:
> 
> XMLWriter writer = new XMLWriter( new FileWriter( "output.xml"));
>         writer.write( document );
>         writer.close();

Secondly; avoid using a FileWriter to write your output, this will not handle 
encodings correctly, use an OutputStream instead:

XMLWriter writer = new XMLWriter( new FileOuputStream( new File(
"output.xml")));
        writer.write( document );
        writer.close();

Regards,
Edwin


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to