2011-09-22 64 views
0

可能重複我解析XML從HTTP服務器來:
Parsing the XML Response in an Android Application如何可以使用Android

我使用下面的代碼

 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> 

請幫

+3

先做研究。這裏是[如何解析XML文件](http://www.ibm.com/developerworks/opensource/library/x-android/)。這裏的人不會爲你做這件事。如果您在解析時遇到特定問題,您將受到支持。 – Knickedi

回答

2

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

+0

請考慮修改[您的答案包含exampledepot.com的鏈接](http://stackoverflow.com/search?q=user%3A115145+url%3A%22http%3A%2F%2Fexampledepot.com*%22)(這裏有還有一個命中與[www](http://stackoverflow.com/search?q=user%3A115145+url%3A%22http%3A%2F%2Fwww.exampledepot.com*%22))通過固定鏈接指向官方資源(在這種情況下,來自Android本身),或者將鏈接替換爲更可靠的社區控制資源(例如維基百科甚至另一個SO答案),或者僅刪除鏈接。 – BalusC