Solved

UTF-8 rendering problem in JTree with XML

Posted on 2010-09-03
7
631 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

708 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

12 Experts available now in Live!

Get 1:1 Help Now