androidparsingopml

How we can parse OPML String


I got the following String as response when I post the url via HttpPost. My problem is how can I parse this string.

<?xml version="1.0" encoding="UTF-8"?>

<opml version="1">

    <head>
    <status>200</status>
        </head>

    <body>

<outline type="object" text="account">

<account>

  <guide_id>u36710162</guide_id>

  <username>xyz</username>

  <session_id>9d28d854-bd31-4bba-9a5f-4e5cd88edaac</session_id>

  <first_name />

  <last_name />

  <email>xyz@gmail.com</email>

</account>

</outline>

    </body>

</opml>

How can I get the status, guide_id, username, session_id, first_name, last_name and email from this string.

Thanks in Advance ...!!!


Solution

  • It is a XML format response. You can parse it by SAXParser, DOMParser or Xmlpullparser.

    About status that you can get it from HTTP itself

    HttpClient httpclient = new DefaultHttpClient();
    HttpResponse response = httpclient.execute(httpRequest);
    response.getStatusLine().getStatusCode()
    

    Note: Consider <account> as your parent tag.