• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing Russian characters to XML file

 
Guru Rao
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to write few Russian characters into a XML file using XStream. I am using unicode encoding "UTF8". Most of the Russian characters are getting written correctly, but not all.

Here is the code I am using:-

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

public class Test {

public static void main(String[] args) {

String str = null;

try {

str = Util.getRussianChar();

XStream xstream = new XStream(new DomDriver());
xstream.alias("test", A.class);

A a = new A();
a.setTest(str);


File file = new File("d:\\Russian1.xml");
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter
(new FileOutputStream(file),"UTF8"));
bufferedWriter.write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
//bufferedWriter.write("<?xml version=\"1.0\" encoding=\"UTF-8?>");
bufferedWriter.newLine();
xstream.toXML(a, bufferedWriter);


} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

The value in String "str" is "Сибирь/Дальний восток". Here is my code of A.java :-

public class A {

String test;

/**
* @return the test
*/
public String getTest() {
return test;
}

/**
* @param test the test to set
*/
public void setTest(String test) {
this.test = test;
}

}

And here is the Russian1.xml :-

<?xml version="1.0" encoding="ISO-8859-1"?>

<test>
<test>Сибирь/Дальний во�?ток</test>
</test>

As can be seen above in the XML file, few Russian characters are not written correctly into the file.

Any idea what has gone wrong?

Regards,
Guru
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it's UTF-8 you're writing to the file, then you had better specify that as the encoding in the XML file, hadn't you? You're specifying ISO-8859-1 (which does not include any Russian characters, AFAIK). Also note that it's called "UTF-8", not "UTF8".
 
Guru Rao
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I have already tried those options, but the result is same.
 
ravi pardeshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


add this one in your web.xml file.
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your input, but what makes you think this is about servlets or JSP files?
 
ravi pardeshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i had this problem for Chinese characters. i solved that one using that filter.


 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sure it did, but it won't work with normal Java applications, now will it?
 
ravi pardeshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohh sory ...

i forgot that one.

he is doing for standalone application.
no idea about this.
 
Guru Rao
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The issue is fixed.
Sorry guys, the problem was not in the program posted by me. The issue was with the Utility which retrieved the Russian characters, that is "str = Util.getRussianChar(); "

Anyways, thanks for all your inputs.

Regards,
Guru
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't you just hate it when that happens? You spend so long trying to find out what's wrong in your code, only to find some third party code has a bug...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic