目前我正在使用 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>rahul.jain@abc.in</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>
如何解析这种格式?