Dom xml parsing in android

I'm new to android development, I don't know how to parse data from xml, so please help.

this is my Xml I have to parse.

        <FeedPath>how r u</FeedPath>


Thanx in advance.


source to share

2 answers

I don't understand why people are asking this question here without searching the net properly. Please remember this web search before asking for anything here. Below is the link where you can find a very good xml parsing tutorial ...



My suggestion starts with a basic step:

  • think about your connection to the xml: url file? local?
  • DocumentBuilderFactory instance and builder

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


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

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

XML file parsing:

XmlDom document = dBuilder.parse (xmlFile);

After that, it turns the xml file into a DOM or Tree structure and you need to move node to node. In your case, you need to get content. Here's an example:

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

        NodeList nList = doc.getElementsByTagName(tagName);
            Element eElement = (Element)nList.item(0);
            String ranking = eElement.getTextContent();
                result = String.valueOf(ranking);

        return result;


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

Good luck!



All Articles