Solved

ChangedCharSetException From Swing Parser

Posted on 2004-04-13
7
812 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

746 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

11 Experts available now in Live!

Get 1:1 Help Now