Reading data from XML document


Last Updated:

  1. kaibuki

    kaibuki New Member This Topic's Starter

    Joined:
    Apr 8, 2010
    Messages:
    4
    Likes Received:
    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!
     

    Advertisement
  2. tommoor

    tommoor Member

    Joined:
    Apr 11, 2010
    Messages:
    23
    Likes Received:
    1
  3. kaibuki

    kaibuki New Member This Topic's Starter

    Joined:
    Apr 8, 2010
    Messages:
    4
    Likes Received:
    0
    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 New Member

    Joined:
    Dec 29, 2010
    Messages:
    1
    Likes Received:
    0
    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...