1. Download our Official Android App: Forums for Android!

Apps Reading data from XML document

Discussion in 'Android Development' started by kaibuki, Apr 12, 2010.

  1. kaibuki

    kaibuki Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Apr 8, 2010

    Apr 8, 2010
    4
    0
    5
    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!
     

    Advertisement

  2. tommoor

    tommoor Newbie
    Rank:
    None
    Points:
    36
    Posts:
    23
    Joined:
    Apr 11, 2010

    Apr 11, 2010
    23
    1
    36
  3. kaibuki

    kaibuki Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Apr 8, 2010

    Apr 8, 2010
    4
    0
    5
    Thanx tommoor!

    but I am looking for a compelete sample code.
    as the sample code available online, is only able to read one node, I want to read all the node.

    Looking forward for replies..

    Thanks!!
     
  4. malar

    malar Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Dec 29, 2010

    Dec 29, 2010
    1
    0
    5
    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()]);
     

Share This Page

Loading...