How can i read the more attribute values on single document.
This is xml sample xml file:
<Categories>
<Category name="Title 1"
<SubCategory>
<subcategory title="subtitle 1" id="1" ></subcategory>
<subcategory title="subtitle 2" id="2" ></subcategory>
<subcategory title="subtitle 3" id="3" ></subcategory>
</SubCategory>
</Category>
<Category>
<Category name="Title 2"
<SubCategory>
<subcategory title="subtitle 4" id="4" ></subcategory>
<subcategory title="subtitle 5" id="5" ></subcategory>
<subcategory title="subtitle 6" id="6" ></subcategory>
</SubCategory>
</Category>
</Categories>
Here i have to display the category name and subcategory title.i have used below code and i have to run the app which means am getting the category name but i didn't get the subcategory title name..how can i get the subcategory title name ... pls give me any idea..
i have declared
static String KEY_CATEGORY = "Categories";
static final String KEY_TITLE = "Category";
static final String KEY_ARTICLE = "SubCategory";
After that i have to create the nodelist and tag the category name.
NodeList nl = doc.getElementsByTagName(KEY_TITLE);
NodeList nl1 = doc.getElementsByTagName(KEY_ARTICLE);
Also add the all category name on map..so i have used for loop;
for (int i = 0; i < nl.getLength(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
map.put( KEY_TITLE,(e.getAttribute("name")));
for (int j = 0; j < nl1.getLength(); j++) {
map.put( KEY_ARTICLE,((Element)nl1.item(i)).getAttribute("title"));
}
songsList.add(map);
}
}
Here am getting category name ...but i can't get the all subcategory title name...am getting only first 2 subcategory title name ...whats wrong in my code...i have used for loop within for loop..first for loop for get the category name and second for loop for getting the subcategory title...total category is 2...but subcategory is 6...thats y am getting 2 subcategory title alone i mean its depends upon total category count..if yes means how can i do for getting all subcategory title ????pls give me solution for getting the all subcategory title name...give me any idea ???