开发者

How can I parse xml coming from http server using android [duplicate]

This question already has an answer here: Closed 11 years ago.

Possible Duplicate:

Parsing the XML Response in an Android Application

I am using following code

     public void executeHttpGet() throws Exception {
        dialog = new ProgressDialog(this);
        dialog.setCancelable(true);

        // set a message text
        dialog.setMessage("Loading...");

        // show it
        dialog.show();
         BufferedReader in = null;

         DefaultHttpClient client = new DefaultHttpClient();
         HttpGet request = new HttpGet();
         String url=   "http://newdev.objectified.com/morris/interface/mobile.php?method=dealerLogin&username=zzzzz&password=zzzz";

         String login = "zzzzz";
         String pass = "zzzzz";

         client.getCredentialsProvider().setCredentials(new AuthScope("newdev.objectified.com", 80), new UsernamePasswordCredentials(login, pass));

         request.setURI(new URI(url));
         HttpResponse response = client.execute(reque开发者_Python百科st);

                in = new BufferedReader
                (new InputStreamReader(response.getEntity().getContent()));
                StringBuffer sb = new StringBuffer("");
                String line = "";
                String NL = System.getProperty("line.separator");
                while ((line = in.readLine()) != null) {
                    sb.append(line + NL);
                }
                in.close();
                String page = sb.toString();
                Toast.makeText(this, page, Toast.LENGTH_LONG).show();
             //  dialog.dismiss();


        }

Now I want to parse the coming xml which is

<?xml version="1.0"?>
<response>
 <sid>kjdci120ts32e30akcj42acaf0</sid>
  <dnumber>dealer</dnumber>
 <dtitle>Test User</dtitle>
  <dcity>karachi</dcity>
  <dprovince>sindh</dprovince>

  <dcountry></dcountry>
  </response>

Please help


Use SAX, or the DOM, or the XmlPullParser, all of which are available in Android.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜