//URL_FEED Example: http://jovemnerd.ig.com.br/feed/rss/
final HttpGet httpget = new HttpGet(URL_FEED);
//Connect
final HttpResponse response = httpclient.execute(httpget);
//Get Entity connection
HttpEntity entity = response.getEntity();
//Get InputStream
InputStream feed = entity.getContent();
...
//Convert InputStrean to InputSource
final InputSource source = new InputSource(feed);
//If encondind is not detect , then read head xml and set enconding
if(source.getEncoding()==null){ //THIS THE PROBLEM
//The enconding is null, but in entity have head with type enconding
source.setEncoding(getEncondingFromEntity(entity));
}
/*Now your InputSource have the correct enconding, then use "source" in your parse. Ex:*/
final XMLReader xmlreader = parser.getXMLReader();
final RSSHandler handler = new RSSHandler(config);
xmlreader.setContentHandler(handler);
xmlreader.parse(source);
...
private String getEncondingFromEntity(HttpEntity entity){
if(entity.getContentType()!=null){
//Content-Type: text/xml; charset=ISO-8859-1
//Content-Type: text/xml; charset=UTF-8
for(String str : entity.getContentType().getValue().split(";")){
if(str.toLowerCase().contains("charset")){
return str.toLowerCase().replace("charset=","").replace(";","").replace(" ","");
}
}
}
return null;
}