【问题标题】:How can I parse xml coming from http server using android [duplicate]如何使用android解析来自http服务器的xml [重复]
【发布时间】:2011-09-22 15:45:24
【问题描述】:

可能重复:
Parsing the XML Response in an Android Application

我正在使用以下代码

     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(request);

                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();


        }

现在我要解析即将到来的 xml 这是

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

  <dcountry></dcountry>
  </response>

请帮忙

【问题讨论】:

  • 先做研究。这是how you parse a XML file。这里的人不会为你这样做。如果您在解析时遇到特定问题,我们将为您提供支持。

标签: android xml-parsing


【解决方案1】:

使用SAX,或DOM,或XmlPullParser,所有这些都在Android 中可用。

【讨论】:

  • 请考虑修改your answers containing links to exampledepot.comwww 也有一个命中),方法是修复指向官方资源的链接(在这种情况下,来自 Android 本身),或者替换链接到更可靠的社区控制资源(例如 Wikipedia 甚至另一个 SO 答案),或者只是删除链接。
猜你喜欢
  • 1970-01-01
  • 2019-07-06
  • 1970-01-01
  • 2013-11-11
  • 2019-10-17
  • 1970-01-01
  • 1970-01-01
  • 2021-06-20
  • 1970-01-01
相关资源
最近更新 更多