我正在開發一個android應用程序,我必須從.Net webservice獲取數據最初webservice的方法返回簡單的字符串。這很好,我的代碼工作正常,順利地獲取字符串。但是我的問題在方法返回對象時開始,我知道對象以XML形式保存數據。我也通過調試我的代碼來確認它,結果對象保存下面給出的數據。在android中查詢xml解析
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<UserInfoResponse xmlns="http://tempuri.org/">
<UserInfoResult>
<UserName>Himanshu</UserName>
<Email>[email protected]</Email>
</UserInfoResult>
</UserInfoResponse>
</soap:Body>
</soap:Envelope>
和我的代碼使用的Web服務是: -
public void objData(){
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME2);
Log.d("request", request.toString());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
Log.d("envelope", envelope.toString());
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
Log.d("envelope", envelope.toString());
HttpTransportSE aht = new HttpTransportSE(URL);
aht.debug=true;
Log.d("aht", aht.toString());
try
{
aht.call(OBJ_SOAP_ACTION, envelope);
SoapPrimitive results = (SoapPrimitive)envelope.getResponse();
System.out.println("results="+results);
tv4.setText(""+results);
}
catch (Exception e)
{
tv4.setText(e.getClass().toString());
Log.d("Error",e.getClass().toString());
}
}
對象results
包含XML data.Now我的問題是,當我使用的代碼打印對象的數據tv4.setText(""+results);
它給我class java.lang.ClassCastException
。我知道這是不正確的方法來獲取對象的XML數據,我不得不解析它。但我不知道如何解析對象。所以請幫助我解析XML包含object.Any幫助將高度讚賞。提前告知。
如果您需要更多說明,請與我聯繫... – Rakhita 2012-02-13 06:52:02