Link to home
Start Free TrialLog in
Avatar of __geof__
__geof__Flag for Norway

asked on

UTF-8 rendering problem in JTree with XML

Hi everyone.

I have a problem that I can't figure out. I want to show a list of folder in a JTree. I download the list as an XML file from a server and have 2 issues when showing them in the tree.
1. Non latin char are not displayed correctly
2. Rendering in the node stops after special char (haven't tested them all but "&" char is a problem.

Here is an XML sample:
<?xml version="1.0" encoding="UTF-8"?>
    <path>/01_Lancôme</path>  //ô is displayed like oÌ,
    <path>/V&R</path>  //&R is not displayed at all

If I read it in a web browser, everything looks fine. I use the DefaultTreeCellRenderer and DefaultMutableTreeNode. Also when I print to System.out, it shows up correctly.

Any ideas?

Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

Avatar of __geof__


Quite right you are. I should have mentioned it but I actually escape the & in Java, if not, it doesn't parse at all.
But it doesn't help either. Either & nor &amp; displays correctly.
did you tried jakarta commons?

Also mention the exception that you get
didn't help :(
other ideas?
OK. My bad. I had a wrong parsing in the toString method of the object in the node. But the UTF-8 problem is still the same. Non latin char are not displayed correctly. Some thoughts?
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK. Found it. The client used to download the xml file was latin1 so I had to force it into UTF-8.

I give you some points as thanks for the help.