Parsing XML in Android (DOM method)

This is a simple example parsing twitter xml in Android

Here is the sample tweet data (one entry is one tweet)

Parsing XML with DOM method is an iterative process.
As you can see below, continuously use NodeList and Node object to explore the elements of XML document
In this example, I extracted <name> element under the <author>

Tags: , ,

4 Responses to “Parsing XML in Android (DOM method)”

  1. dootzky says:

    dude,this code would’ve been much more helpful if it could be copy-pasted or downloaded.
    it’s almost impossible to retype this without any errors

    but thanks anyway for the effort ;)

  2. Apurv Gupta says:

    Try this it is almost similar and working :)

    private void MyXmlParser(string url) {
    TextView tv1 = (TextView) findViewById(;

    try {

    URLConnection urlConn = url.openConnection();
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(urlConn.getInputStream());

    NodeList nodeList = doc.getElementsByTagName(“Response”);
    /** Assign textview array lenght by arraylist size */
    int res_count = nodeList.getLength();
    for (int i = 0; i < nodeList.getLength(); i++) {
    Node node = nodeList.item(i);


    } catch (Exception e) {

    tv1.setText("error" + e.getMessage());



  3. it was just amazing information sharing with informative content. I appreciate your blog because of unique content. Thanks for that.

  4. its great i am looking for this last 1 week and finally i got my solution love it :)

Leave a Reply

You must be logged in to post a comment.