I need to parse the XML file in my android application. I dont know how many nodes it got <p>My activity class look like this:</p> <pre><code>AssetManager assetmgr= getAssets(); String list[] = assetmgr.list("subdir"); if (list != null) { DocumentBuilder builder =DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = builder.parse(getAssets().open("subdir/fullSurvey.xml")); </code></pre> <p>xml object class looks like this:</p> <pre><code>NodeList root = doc.getElementsByTagName("root"); NodeList nlQuestions = root.item(0).getChildNodes(); QuestionObject[] allQuestions = new QuestionObject[nlQuestions.getLength()]; for (int i = 0; i &lt; nlQuestions.getLength(); i++) { Node question = nlQuestions.item(i); NodeList childNodes = question.getChildNodes(); QuestionObject x = new QuestionObject(); for (int j = 0; j &lt; childNodes.getLength(); j++) { Node child = childNodes.item(j); if (child.getNodeName() !="#text") { Questions t = Questions.valueOf(child.getNodeName()); // etc. </code></pre> <p>I dont know how to parse xml file according to attribute value</p>