Solved

UTF-8 rendering problem in JTree with XML

Posted on 2010-09-03
7
634 Views
Last Modified: 2012-05-10
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"?>
<volumes>
  <volume>
    <path>/01_Lancôme</path>  //ô is displayed like oÌ,
  </volume>
  <volume>
    <path>/V&R</path>  //&R is not displayed at all
  </volume>
</volumes>

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?

Tx
0
Comment
Question by:__geof__
  • 4
  • 3
7 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33595843
0
 
LVL 6

Author Comment

by:__geof__
ID: 33595874
gurvinder372:
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.
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33595900
did you tried jakarta commons?
http://www.javalobby.org/java/forums/t19288.html

Also mention the exception that you get
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 6

Author Comment

by:__geof__
ID: 33596140
didn't help :(
other ideas?
0
 
LVL 6

Author Comment

by:__geof__
ID: 33596716
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?
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 33596753
0
 
LVL 6

Author Closing Comment

by:__geof__
ID: 33597343
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.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to monitor the number of connections/threads being utilized on Tomcat 6.0 8 70
varialbe initialization 11 32
MySQL  on Tomcat 8 44
How do I remove an object from a 3 23
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question