Link to home
Start Free TrialLog in
Avatar of PuneetKSaxena
PuneetKSaxena

asked on

Write Russian chars in a xml file

HI ,

I want to read and write russian chars in a xml file from Java code
When i try , encoding="UTF-8", I'm getting ??????????  in xml file

How can i read and write russian chars in Java
Any help in this regard will be highly appreciated

Thanks and Regards
Puneet
Avatar of Mick Barry
Mick Barry
Flag of Australia image

how are you viewing the xml?
make sure what you are viewing with and the font it is using supports russian

can u post your current code

Avatar of isaackhazi
isaackhazi

Save your xml-file as utf-8 and change the first line into:

<?xml version="1.0" encoding="UTF-8" ?>
Possible you were using a font before that didn't have those characters in it? Some fonts only have certain characters available.
Avatar of PuneetKSaxena

ASKER

Hi,

I'm reading a html file which contains russian chars, through URL connection (code snippet as below).
Now after parsing this html(which contains russian chars), i'm constrcuting a xml which contains russian chars.

When i view this xml, the russian chars are coming as ?????????, so i'm not able to understand anything from this.

Now i've to use this xml file in Adobe Flex, which again gives me ????????



Hope it clarifies
try {
urlIviewPath =new URL(strIviewURLPath+ "&j_user="+ strUserId "&j_password="+ strPassword);
urlIviewPath = Util.encodeUrl(urlIviewPath);//encode the russian chars in URL
urlConnection = urlIviewPath.openConnection();
urlConnection.connect();
br =new BufferedReader(new InputStreamReader(			urlConnection.getInputStream(), "UTF-8"));
} catch (RuntimeException e2) {
}

Open in new window

are you sure its utf8, whats the encoding when you load with browser?
how do oyou write them, make sure you use UTF8 there as well

Whille writing xml i'm using
<?xml version="1.0"  encoding="UTF-8"  ?>.
try to use
<?xml version="1.0"  encoding="UTF-16"  ?>.
You must read the page in the correct encoding and preserve that encoding when you write it to xml, which you should do with an OutputStreamWriter

http://java.sun.com/javase/6/docs/api/java/io/OutputStreamWriter.html#OutputStreamWriter(java.io.OutputStream,%20java.lang.String)

You need to view the results with a program that supports that encoding, and (afaik) that doesn't include a Windows console for UTF-8
final String ENCODING = urlConnection.getContentEncoding();
br = new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), ENCODING));

Open in new window

Thats works for me . But now in xml instead of ???????? i'm getting chars like РуÑ?Ñ?кий/По типу

Any suggestion :)
so you change the write encoding as I suggested earlier? If so, what did u change it to?
And have you checked how the page is encoded?

You haven't answered my earlier question about how you are reading it with. You need to use something that supports displaying russian and has an appropriate font.

does it look the same in flex?


>>But now in xml instead of ???????? i'm getting chars like ÐÂ

Well unfortunately, i can't read that here ;-). Can you post a screenshot, showing your application window?
ASKER CERTIFIED SOLUTION
Avatar of beekeep
beekeep
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial