Skip to content Skip to sidebar Skip to footer

Dom Xml Parsing In Android

i am new in android development, i don't know how to parse data from xml, so please help. this is my Xml which i have to parse.

Solution 1:

I dont understand that why people ask the question here without searching properly on net.Please do remember that search on net before asking anything here.... Below is the link where you can find a very good tutorial about xml parsing...

http://www.androidpeople.com/android-xml-parsing-tutorial-%E2%80%93-using-domparser


Solution 2:

My suggestion is starting from the basic step:

  1. think about your xml file connection: url? local?
  2. instance a DocumentBuilderFactory and a builder

DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();

OR

URLConnection conn = new URL(url).openConnection();
InputStream inputXml = conn.getInputStream();

DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance() .newDocumentBuilder(); Document xmlDoc = docBuilder.parse(inputXml);

Parsing XML file:

Document xmlDom = dBuilder.parse(xmlFile);

After that, it turns a xml file into DOM or Tree structure, and you have to travel a node by node. In your case, you need to get content. Here is an example:

String getContent(Document doc, String tagName){
        String result = "";

        NodeList nList = doc.getElementsByTagName(tagName);
        if(nList.getLength()>0){
            Element eElement = (Element)nList.item(0);
            String ranking = eElement.getTextContent();
            if(!"".equals(ranking)){
                result = String.valueOf(ranking);
            }

        }
        return result;
    }

return of the getContent(xmlDom,"MediaTitle") is "hiiii".

Good luck!


Post a Comment for "Dom Xml Parsing In Android"