I am reading in a UTF-8 XML SVG document I process it Then I wish to output it However the encoding is different from the original document, it should remain as UTF-8 SVG Editor Inkscape rejects the document because of this
I have searched "UTF-8", "encoding" and both terms but can't find a problem even similar to mine Here is my code to output the file (solution 1): DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance( ); DOMImplementationLS lsImpl = (DOMImplementationLS)registry.getDOMImplementation("LS"); /* Serialize the document */ LSSerializer serializer = lsImpl.createLSSerializer( ); LSOutput output = lsImpl.createLSOutput( ); output.setEncoding("UTF-8"); System.out.println( "encoding: " + output.getEncoding() ); output.setCharacterStream(new FileWriter(new File("C:\\file.svg"))); output.setCharacterStream( stringWriter ); serializer.write(doc, output); Here is the fragment of the file where the encoding is different: input svg xml file: <glyph horiz-adv-x="833" unicode="©"> etc... - inkscape can read output svg file: <glyph horiz-adv-x="833" unicode="©"> etc... - inkscape says it cannot read -because it is not proper UTF-8 - i know this because if i remove the line, then inkscape can open the file ok However if I use the following code (solution 2) it works - i.e. the encoding is correct, *BUT* this method uses StringBuffers which are not large enough - only part of the file gets written so I need to use solution (1) above really. This proves to me it is the output encoding and NOT anything to do with the input parsing. Solution 2: DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance( ); DOMImplementationLS lsImpl = (DOMImplementationLS)registry.getDOMImplementation("LS"); /* Serialize the document */ LSSerializer serializer = lsImpl.createLSSerializer( ); LSOutput output = lsImpl.createLSOutput( ); StringWriter stringWriter = new StringWriter(); output.setCharacterStream( stringWriter ); FileOutputStream fileOutputStream = new FileOutputStream( "C:\\file.svg" ); OutputStreamWriter outputStreamWriter = new OutputStreamWriter( fileOutputStream, "UTF-8" ); outputStreamWriter.write( stringWriter.toString() ); -- View this message in context: http://www.nabble.com/LSoutput-setEncoding%28%22UTF-8%22%29-ignored---output-XML-not-UTF-8-compliant-tp15988542p15988542.html Sent from the Xerces - J - Users mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]