Solved

ChangedCharSetException From Swing Parser

Posted on 2004-04-13
7
822 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 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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:
This video teaches viewers about errors in exception handling.

733 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