How to set UTF-8 for parsed XML file using SAX Parser in android

advertisements

I am parsing an XML file obtained from the remote server,which consists of some different fonts using SAX Parser and I want to set UTF-8 to this.How can I set?

Code is:

SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();
                   /** Send URL to parse XML Tags */
        URL sourceUrl = new URL(myURL);
        /** Create handler to handle XML Tags ( extends DefaultHandler )*/
        MyXMLHandler myXMLHandler = new MyXMLHandler();
        xr.setContentHandler(myXMLHandler);
        xr.parse(new InputSource(sourceUrl.openStream()));

Waiting for the help from SO,

Thanks.


Use below code to parse xml response.

Xml.parse(in, Xml.Encoding.UTF_8, contentHandler);