Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ChangedCharSetException From Swing Parser

Posted on 2004-04-13
7
Medium Priority
?
829 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 4

Accepted Solution

by:
bkfirebird earned 500 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This video teaches viewers about errors in exception handling.
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 …
Suggested Courses

688 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