4

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.

Community
  • 1
  • 1
Vivek Kalkur
  • 2,200
  • 2
  • 21
  • 40

2 Answers2

2

Use below code to parse xml response.

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

Shachillies
  • 1,616
  • 14
  • 12
1

You can setup the encoding in your InputSource: http://developer.android.com/reference/org/xml/sax/InputSource.html

It has got a method setEncoding(String encoding) - set that to "UTF8"

Tim
  • 6,692
  • 2
  • 25
  • 30