File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes How to parse an XML document containing Chinese characters and get an XML bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to parse an XML document containing Chinese characters and get an XML bean" Watch "How to parse an XML document containing Chinese characters and get an XML bean" New topic
Author

How to parse an XML document containing Chinese characters and get an XML bean

ragunath Mariappan
Greenhorn

Joined: Oct 29, 2007
Posts: 8
Hello all,

(1) I parsed an XML document containing Chinese characters and got the XML bean as below:



(2) Then I tried to store it in a file as below:



(3) When I open "chineseCharsFile.xml" in a text editor, I'm able to see the Chinese characters, but when I open "newChineseCharsFile.xml" in the same text editor I'm not able to see the Chinese characters.


Any suggestions, please?


Thanks,
Ragu
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42929
    
  68
If you don't specify an encoding when writing files, the platform default encoding will be used - which in all likelihood doesn't support Chinese characters. You can use an OutputStreamWriter wrapped around a FileOutputStream to accomplish this.
Jair Rillo Junior
Ranch Hand

Joined: Aug 27, 2008
Posts: 114
Besides the enconding, I suggest you to take a look at XStream framework. It is very useful when you want parse/generate XML to BEAN and vice-versa.


Regards, Jair Rillo Junior
http://www.jairrillo.com/blog, SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 5.0, IBM SOA Associate (Test 664).
ragunath Mariappan
Greenhorn

Joined: Oct 29, 2007
Posts: 8
Hello Ulf,

It worked after I wrapped OutputStreamWriter with BufferedWriter.




Thank you,
Ragu
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

ragunath:
It worked after I wrapped OutputStreamWriter with BufferedWriter.


Just to keep you informed, it is not the BufferedWriter but the OutputStreamWriter that did the trick for you.


apigee, a better way to API!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to parse an XML document containing Chinese characters and get an XML bean