目前我正在使用Android中的XML解析。我不知道它是如何工作的。我使用下面的代碼:如何在Android中實現XML解析?
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(MobileServiceConst.URL);
MultipartEntity reqEntity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("method", new StringBody(MobileServiceConst.UPLOAD_CONTACTS));
reqEntity.addPart("user_id", new StringBody(String.valueOf(Constants.userData.getUserInfo().getuserId())));
reqEntity.addPart("accesstoken", new StringBody(Constants.userData.getMYToken()));
reqEntity.addPart("data",new StringBody(jsnConts.toString()));
reqEntity.addPart("device_id",new StringBody(regId));
postRequest.setEntity(reqEntity);
HttpResponse response = httpClient.execute(postRequest);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
StringBuilder s = new StringBuilder();
while ((sResponse = reader.readLine()) != null) {
s = s.append(sResponse);
}
sResponse = s.toString();
System.out.println("responseeeeeeeeeeeeeee"+sResponse);
的sResponse是按以下格式:
<CS_Mservice_Main generator="check" version="1.0">
<getContacts>
<mycnt>
<key_0>
<id>1</id>
<user_id>22434</user_id>
<device_id>121212,</device_id>
<contact_id></contact_id>
<firstname></firstname>
<lastname></lastname>
<email></email>
<email1></email1>
<email2></email2>
<contact1>9809788201</contact1>
<contact2></contact2>
<contact3></contact3>
<contact4></contact4>
<created_at>2013-03-18 13:29:12</created_at>
</key_0>
<key_1>
<id>16</id>
<user_id>17025</user_id>
<device_id>APA91bGRyoeOlxZjhfjkdshjsdfsdsdf9kICZFsveU_QonqbNIbYONWLtiHpT4CmPe1aJg3rZ86noqj2HKshgZRlk1dc0Em7AVte2usHaP-qRzVBcP8BWzJuXa8ozA</device_id>
<contact_id></contact_id>
<firstname>Rahul</firstname>
<lastname>Jain</lastname>
<email>[email protected]</email>
<email1></email1>
<email2></email2>
<contact1></contact1>
<contact2></contact2>
<contact3></contact3>
<contact4></contact4>
<created_at>2013-03-18 13:30:04</created_at>
</key_1>
</mycnt>
<email/>
<sms/>
<status>success</status>
</getContacts>
</CS_Mservice_Main>
如何可以解析這種格式?
有什麼理由http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html 不會工作? – Arveen 2013-03-19 04:30:11
哪個標籤可以解析並顯示在手機中? – 2013-03-19 04:31:30
我需要解析所有細節並將其存儲在單獨的數組列表中 – jithu 2013-03-19 04:33:54