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

I am parsing an XML file received from a remote server that consists of several different fonts using SAX Parser , and I want to configure UTF-8 to do this. How can i install?

Code:

 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 help from SO,

Thanks.

+4
source share
2 answers

Use the code below to parse the XML response.

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

+2
source

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

He has a setEncoding(String encoding) method - set it to "UTF8"

+1
source

Source: https://habr.com/ru/post/1381122/


All Articles