[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 369
  • Last Modified:

Writing multilingual XML files using Java

Hi,
I am trying to write multilingual XML files through java and somehow the non-English part is not written correctly.  

The XML text is being read from a database which supports UTF-8.

I have used OutputStreamWriter with Charset "UTF-8" to write to the xml file.
(While executing the Java prg in Eclipse IDE I am also printing the XML text to console.
 If I change my Regional settings and select the different language , those charaters are printed
 to console correctly.
 If I keep my language settings to English(United States) it won't print the non-English characters  properly.)

In anycase the XML file that is generated always has the non-English charaters incorrect.

Any idea to get around this?
0
pratikbm
Asked:
pratikbm
  • 10
  • 8
  • 6
3 Solutions
 
CEHJCommented:
Make sure you set Eclipse to use UTF-8
0
 
objectsCommented:
> If I keep my language settings to English(United States) it won't print the non-English characters  properly.)

That could just be because the font being used does not contain the appropriate characters.

> In anycase the XML file that is generated always has the non-English charaters incorrect.

What exactly makes u tyhink that, above you stated that it displays correctly if regional setting change. Which implies the content is correct.

0
 
pratikbmAuthor Commented:
I have edited the project properties to use "Text File encoding" as UTF-8 but still the same results.
(I am using Rational Application Developer)

Also I was wondering if the problem is in my Java Code since it is the one which writing the XML file
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
pratikbmAuthor Commented:
On changing the language settings the characters are printed correctly only on the console but in the actual XML file they are incorrect.

So I guess it gets the correct content from the database but while writing to the
file it does something wrong.
0
 
objectsCommented:
> but in the actual XML file they are incorrect.

how are you determining that

0
 
pratikbmAuthor Commented:
Well I am using this XML file to generate PDF file using the XSL-FO and those
characters are rendered in correctly.

I tried this....
1.) I opened the XML file in RAD manually and copy paste those characters.  Now when I generate the PDF file the characters are rendered fine.
So I conclude that my XSL file which specifies the font (Arial Unicode) is fine.

2.) Also I have written a small .asp page which simply reads the data from the
database and displays on the webpage.  Over there also the characters looks
okay.  So I believe the database has those characters correct.
 
So I think something has to be wrong with the XML.
0
 
CEHJCommented:
>>1.) I opened the XML file in RAD manually and copy paste those characters

And what did it look like *before* you copy-pasted them
0
 
objectsCommented:
i'm confused, everything you mentioned above rendered correctly :) What is not rendering correctly?
Are you embedding the necessary font in the generated pdf?
0
 
pratikbmAuthor Commented:
Before copy paste ... they all looked like some junk characters (बबहà¤" à¤Üधà¤Ü धठ)

As mentioned I have an asp page which displays this data on webpage,   I copied them from that webpage and pasted in the XML file.

And then the XML and the pdf both looked fine.
0
 
objectsCommented:
is the content type of the web page ok? and a supported font being used?
0
 
CEHJCommented:
If you put the file somewhere public, we can have a look at it
0
 
pratikbmAuthor Commented:
I have uploaded the relevant files to following url..

http://www.hotlinkfiles.com/files/152953_o3eqr/multilingual%20XML.zip]multilingual%20XML.zip

Also I have used following code to open the file stream for writing the XML file...

Writer xmlfile = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("c:/ccm.xml"), "UTF-8"));
0
 
CEHJCommented:
What do you intend the first foreign character to be - what is the Unicode symbol?
0
 
pratikbmAuthor Commented:
You can find the characters being displayed as required in the correct.pdf
0
 
pratikbmAuthor Commented:
I hope that is what you asked...correct me if I am wrong
0
 
pratikbmAuthor Commented:
Hey I finally got what the issue was.....

I was entering the multilingual data in the database through an asp page......and so when displayed by on a asp webpage it showed correctly.

Now I stored the data by harcoding some multilingual string literals throuhg a java program and retrived the data from the same program...
and it all worked fine.

Though not very sure how the data encoding is happening here ....seems like my problem is solved.

Thanks anyways.
0
 
objectsCommented:
> Now I stored the data by harcoding some multilingual string literals

you would need to use unicode encoding to specifying any hardcoded strings.
0
 
pratikbmAuthor Commented:
I am writing the code in RAD IDE with text properties set as Unicode ..... to type in different languages (for the string literals) I change the language setting on my machine .....key in the string literal and then execute the program.....it worked

This was only for testing ...... ofcourse in the actual I will make some arrangements to receive data from end user properly.

0
 
objectsCommented:
moving language specific strings into properties files can make them easier to manage.
0
 
objectsCommented:
and using encoded strings makes them more portable, effectively making them independant of box/file encoding.
0
 
CEHJCommented:
You can use the JDK utility  native2ascii to encode your strings
0
 
pratikbmAuthor Commented:
These options look good ..let me try them out
0
 
CEHJCommented:
:-)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 10
  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now