I have used code from link for parsing xml it worked in versions less than android 2.3 but I am trying to get it done 4.0.3 it doesn't return any value in it at all.How solve this issue.I dont get any errors in the log but I dont get the parsed values as output.Here is the link I used as code
@SuppressWarnings("unused")
public final static Document XMLfromString(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) {
System.out.println("XML parse error: " + e.getMessage());
return null;
} catch (SAXException e) {
System.out.println("Wrong XML file structure: " + e.getMessage());
return null;
} catch (IOException e) {
System.out.println("I/O exeption: " + e.getMessage());
return null;
}
return doc;
}
Use Log.e()
instead of System.out.println()
. You are probably getting an exception, but it isn't shown.
try {
...
} catch (ParserConfigurationException e) {
Log.e(TAG, "XML parse error", e);
return null;
} catch (SAXException e) {
Log.e(TAG, "Wrong XML file structure", e);
return null;
} catch (IOException e) {
Log.e(TAG, "I/O exeption", e);
return null;
}
(where TAG
is a string-constant)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.