Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

saving an xml document in a certain encoding?

  Asked By: Howard    Date: Aug 25    Category: Java    Views: 956
  

I'm trying to write an xml document object into a file, in a
specified encoding not necessarily UTF-8. The code is something like
this:
---
Source source = new DOMSource(document);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new
FileOutputStream(fileName), encoding));
Result result = new StreamResult(out);

// Write the DOM document to the file
Transformer xformer = TransformerFactory.newInstance().newTransformer
();
xformer.transform(source, result);
---

However, after save the header of the xml is always '<?xml
version="1.0" encoding="UTF-8" ?>' . How do I make the header
contain the encoding it's saved in, for example, "SJIS"?

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on saving an xml document in a certain encoding? Or get search suggestion and latest updates.




Tagged: