Solved

UTF-8 rendering problem in JTree with XML

Posted on 2010-09-03
7
632 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now