• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Reading data from XML document

kaibuki

Lurker
Apr 8, 2010
4
0
Hi Guys,

This is my first post on this forum, :)

I am trying to read a XML document from internet and view all the data from it in my app.
unfortunately so far I can only read one node.
any one can help me with the code/suggestions on how to read XML data and display on screen + can later use that data.

Thanks alot..looking forward for replies.

cheers..

Kai!
 
try this code.
ArrayList gridImgId = new ArrayList();
ArrayList gridImgName = new ArrayList();
ArrayList gridImgThump = new ArrayList();
ArrayList gridUrl = new ArrayList();
try
{
URL url = new URL("http://thebeswallpapers.com/api/androidxml.php?action=getCategoryList");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
NodeList nodeList = doc.getElementsByTagName("category");
for(int a = 0; a < nodeList.getLength(); a++)
{
//nodeList.item(0).getChildNodes();
NodeList child=nodeList.item(a).getChildNodes();
String imgid=child.item(0).getFirstChild().getNodeValue();
String imgname=child.item(1).getFirstChild().getNodeValue();
String imgthump=child.item(2).getFirstChild().getNodeValue();
gridUrl.add("http://thebesthdwallpapers.com/wallpapers/"+imgid+"/"+imgthump);
gridImgId.add(imgid);
gridImgName.add(imgname);
gridImgThump.add(imgthump);
}
/*for(int a = 0; a < 10; a++)
{
gridUrl.add("http://www.xyz.com/samples/images/images"+ a +".png");

}*/
}
catch(Exception e)
{
System.out.println("XML Pasing Excpetion = " + e);
}


String[] urls = (String[]) gridUrl.toArray(new String[gridUrl.size()]);
String[] ImageId = (String[]) gridImgId.toArray(new String[gridImgId.size()]);
String[] ImageName = (String[]) gridImgName.toArray(new String[gridImgName.size()]);
String[] ImageThump = (String[]) gridImgThump.toArray(new String[gridImgThump.size()]);
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones