Hi, I tried doing the same but still got the illegal characters. FileOutputStream out = new FileOutputStream("Document.xml"); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8"); XMLWriter xmlWriter = new XMLWriter(out, format); xmlWriter.write(docXML); In the generated xml file, all the apostrophies(') are not readable....Any clues? bejoy
-----Original Message----- From: James Strachan [mailto:[EMAIL PROTECTED] Sent: Monday, November 24, 2003 9:39 AM To: [EMAIL PROTECTED]; Klaus Engelhardt Subject: [dom4j-user] Re: How do I get the encoding in a document? The trick is to use the XMLWriter and use an OutputFormat object to set the encoding. OutputFormat format = new OutputFormat(); format.setEncoding(...) XMLWriter writer = new XMLWriter(format, new FileWriter("foo.xml")); writer.write(someDoc); On 24 Nov 2003, at 13:24, Klaus Engelhardt wrote: > Dear James Strachan, > > I am unable to figure out how to get the original encoding of an XML > document using Dom4j. I have seen email comments, etc. stating that > this is impossible. My question is: is this true? and if so, why? > > The reason I need this is that some documents are in ISO-8859-1 > and others are in UTF-8. If I read in ISO-8859-1 with German > special characters and write it back again as UTF-8, then the resulting > document is no longer viewable with a simple ASCII text editor, at > least as far as the special characters are concerned. So I really do > need to get the original encoding in order to rewrite the modified > document correctly. > > If I have to, I will pre-read the XML document to get the encoding > by hand. But I would really love to spare this hopefully unnecessary > effort! > > If you could send me a comment on this problem or better yet, a > solution, > I would be very happy! > > Thanks, > Klaus Engelhardt > > > > Klaus Engelhardt > Metzstr. 8 > 81667 München > Tel. 0049/89/483491 (home) > Tel. 0049/89/3299-1409 (work) > > James ------- http://radio.weblogs.com/0112098/ ------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ _______________________________________________ dom4j-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-user ------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ _______________________________________________ dom4j-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-user