Solved

ChangedCharSetException From Swing Parser

Posted on 2004-04-13
7
813 Views
Last Modified: 2011-09-20
Hi,
I am trying to parse through the HTML tags using the swing HTML parser.  The problem is that a ChangedCharSetException is thrown when I try to read from certain html files.  I am not quite sure how to go around this.  Thanks for any comments.


HTMLEditorKit.ParserCallback callback = new HTMLEditorKit.ParserCallback(){
    public void handleStartTag(HTML.Tag tag, MutableAttributeSet aSet, int pos){
        <some code>
    }
    public void handleSimpleTag(HTML.Tag tag, MutableAttributeSet aSet, int pos){
        <some code>
    }
};

Reader in = new FileReader(file);
new ParserDelegator().parse(in, callback, false);
0
Comment
Question by:aomega
  • 3
  • 2
  • 2
7 Comments
 
LVL 4

Accepted Solution

by:
bkfirebird earned 125 total points
ID: 10819342
htmlDoc.putProperties("IgnoreCharacterSet",boolean(true));
HTMLEditorKit class cannot interpret <meta> tags as HTML content ..
0
 
LVL 92

Expert Comment

by:objects
ID: 10819401
think you meant:
doc.putProperty("IgnoreCharsetDirective", new Boolean(true));

But what is the htmlDoc you are calling?
0
 
LVL 4

Expert Comment

by:bkfirebird
ID: 10819462
i was referring to the default document ...

i guess a simpler way to do it would be to specify in parse() itself ... change last param to true
new ParserDelegator().parse(in, callback, true);
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.

 

Author Comment

by:aomega
ID: 10819878
Thanks
0
 
LVL 92

Expert Comment

by:objects
ID: 10819893
can you post exactly what you used for the benefit of others.
0
 

Author Comment

by:aomega
ID: 10821354
No problem.

EditorKit kit = new HTMLEditorKit();
Document doc = kit.createDefaultDocument();
doc.putProperty("IgnoreCharsetDirective", new Boolean(true));

kit.read(reader, doc, true);


I actually implemented this by changing the last param to true as bkfirebird pointed out since that was easier: new ParserDelegator().parse(in, callback, true);
0
 
LVL 92

Expert Comment

by:objects
ID: 10821372
Thanks :)
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

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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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.

911 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