我正在創建一個連接到Fogbugz XML API(向API發送請求,接收XML文件)的Android應用程序。現在,我正在創建一個服務來處理這些請求,並分析每個請求以訪問可用的信息。什麼是最好的方法來做到這一點?如果我得到一個inputStream,我應該使用SAX解析器嗎?如何解析XML(Fogbugz XML API)?
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("My URL THAT RETURNS AN XML FILE");
HttpResponse response;
try {
response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
InputStream stream = entity.getContent();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stream));
String responseString = "";
String temp;
while ((temp=bufferedReader.readLine()) != null)
{
responseString += temp;
}
if (entity != null) {
entity.consumeContent();
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
你想用這段代碼實現什麼? – Nealv 2010-07-28 15:32:18
現在,我只是創建並顯示一個字符串,以確保HTTP請求正常工作。完成後,此特定代碼需要登錄到fogbugz並訪問包含令牌的xml文件。但是,在同一服務中,我將使用此令牌在FogBugz中創建,編輯或刪除案例,並且需要能夠解析返回的XML文件以獲取特定信息。 – mbauer14 2010-07-28 15:45:50
順便說一句,FogBugz XML API有其怪癖。在[email protected]與我聯繫,提出任何問題或錯誤。 – 2010-07-30 13:01:50