Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
ragunath Mariappan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ragunath Mariappan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ulf,

It worked after I wrapped OutputStreamWriter with BufferedWriter.




Thank you,
Ragu
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic