• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

DOM : Set Encoding from Cp1252 to UTF-8

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am trying to build a XML Document with DOM that could be parsed
from Xalan XSL Processor.

Creating the Document with a Editor i get the right Result.
But when creating the Document with DOM i get following Error Message :
person.xml; Line 0; Column 0
XSL Error: Could not parse person.xml document!
XSL Error: SAX Exception
org.apache.xalan.xslt.XSLProcessorException: The encoding "Cp1252" is not supported.

The XML File looks like this :
<?xml version="1.0" encoding="Cp1252"?>
<document>
<title>Simple PDF Example</title>
<author>Holger Prause</author>
<note>The following text was taken from the FO Example File readme.fo</note>
<content>Some text</content>
</document>
that why DOM is creating the document with the default Encoding Cp1252
How can i set the encoding to "UTF-8" ?
I didnt found anything about it :-(
Thx,
Holger
 
Holger Prause
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
following will do it :
OutputFormat format = new OutputFormat( document ,"UTF-8",false);
FileWriter fileOut = new FileWriter(new File("person.xml"));
XMLSerializer serial = new XMLSerializer( fileOut, format );
serial.asDOMSerializer();
serial.serialize( document.getDocumentElement() );
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!