I am parsing xml file from SDcard and display it in textview. whenever i tried to access, nothing will displayed
InputStream in = new FileInputStream("/sdcard/jokes.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(in);
doc.getDocumentElement().normalize();
NodeList nodeLst = doc.getElementsByTagName("jokes");
for (int s = 0; s < nodeLst.getLength(); s++) {
Node fstNode = nodeLst.item(s);
System.out.println("" + fstNode);
if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
Element fstElmnt = (Element) fstNode;
NodeList fstNmElmntLst = (NodeList) fstElmnt.getChild("item");
Element fstNmElmnt = (Element) fstNmElmntLst.item(0);
NodeList fstNm = ((Node) fstNmElmnt).getChildNodes();
System.out.println("Number of joke description : "+ ((Node) fstNm.item(0)).getNodeValue());
}
}
This is the code which i did to parse xml file from sdcard. can anyone tell where i made a mistake or if you have better option pls let me know.
Try this for your loop: