Rajan
Rajan

Reputation: 81

how to parse this string in android?

Here is my code

try
        {
            url = new URL("http://localhost/abc//webservice.php?op=login");
            connection = (HttpURLConnection) url.openConnection();
            connection.setDoOutput(true);
            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            connection.setRequestMethod("POST");
            connection.setRequestProperty("user_email", "[email protected]");
            connection.setRequestProperty("user_password", "123456");


            request = new OutputStreamWriter(connection.getOutputStream());
            request.write(parameters);
            request.flush();
            request.close();

            if(connection.getResponseCode() == HttpURLConnection.HTTP_OK)
            {
                String line = "";

                InputStreamReader isr = new InputStreamReader(connection.getInputStream());
                BufferedReader reader = new BufferedReader(isr);
                StringBuilder sb = new StringBuilder();
                while ((line = reader.readLine()) != null)
                {
                    sb.append(line + "\n");
                }
                response = sb.toString();
                isr.close();
                reader.close();

This is my response :

<?xml version ='1.0' encoding ='UTF-8' ?>
   <root>
    <userid>36</userid>
    <message>Successfully Loggin in</message>
   </root>

Please tell me how can I get value of the tags <userid> and <message>

Upvotes: 0

Views: 649

Answers (1)

Vladimir Ivanov
Vladimir Ivanov

Reputation: 43098

Your responce is a simple xml. Parse it with any technology you want:

  1. DOM and SAX
  2. JAXB
  3. SimpleXml

Upvotes: 5

Related Questions