I'm making an android application in which I'm parsing an XML using SAX parser.
In the XML there is tag:
<title>Deals & Dealmakers: Technology, media and communications M&A </title>
As you can see it contains some special charters like &
The issue is I'm using SAX's implicit method:
@Override
public void characters(char[] ch, int start, int length) throws SAXException{}
Here, the parameter 'char[] ch' is supposed to fetch the entire line Deals & Dealmakers: Technology, media and communications M&A
But it is only getting "Deals ".
How can I solve this issue?
One issue might be because of the way I'm passing the XML to the SAX parser. Do I need to change the encoding or format?
Currently, I'm passing the XML as InputStream
& using the below code:
HttpResponse httpResponse = utils.sendRequestAndGetHTTPResponse(URL);
if (httpResponse.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = httpResponse.getEntity();
InputStream in = entity.getContent();
parseResponse(in);
}
// Inside parseResponse method:
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xmlReader = sp.getXMLReader();
MyHandler handler = new MyHandler();
xmlReader.setContentHandler(handler);
xmlReader.parse(new InputSource(in));
} catch (Exception e) {
}