I used a tutorial about listview parsing xm from internet and using LasyAdapter shows the items in listview. When I add persian characters in xml (into one of childnodes) the result is some boxes in listview (after showing the text in listview). The format of xml is UTF-8, too. I used typeface too (but didn’t work). Besides when I type Pwesian into the application it shows alright but it can’t show Persiann content parsed from xml. Thanks in advance. I updated the post with original XMLparser (which was the problem).
public String getXmlFromUrl(String url) {
String xml = null;
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
xml = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// return XML
return xml;
}
public Document getDomElement(String xml) {
Document doc = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
doc = db.parse(is);
} catch (ParserConfigurationException e) {
Log.e("Error: ", e.getMessage());
return null;
} catch (SAXException e) {
Log.e("Error: ", e.getMessage());
return null;
} catch (IOException e) {
Log.e("Error: ", e.getMessage());
return null;
}
return doc;
}
I could find the answer. Thanks from @Serdak. He made me think of reader. In getXMLFromUrl part I should have changed:
xml = EntityUtils.toString(httpEntity);toxml = EntityUtils.toString(httpEntity, "UTF-8");and in getDomElement part I should change:
InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xml));toInputSource is = new InputSource(new ByteArrayInputStream(xml.getBytes("UTF-8")));Please note that “url” and “xml” are both Strings which are called by main activity and are used in XMLparser.jave (which contains both getXmlFromUrl() and getDomElement() ).
These commands are in main activity:
XMLParser parser = new XMLParser();String xml = parser.getXmlFromUrl(URL)
;Document doc = parser.getDomElement(xml);
Best regards.