0
我已經使用Ksoap2連接到這個.NET Web服務,當我輸入用戶ID時,我得到一個xml響應。我只想看到兩個標籤callTitle和callDescription。我不需要其餘部分,並且希望在文本中看到沒有用xml代碼包圍的文字。有人可以幫忙嗎?我無法在線找到教程。Ksoap2解析器xml數據
public class AndroidWebService extends Activity {
/** Called when the activity is first created. */
private static String SOAP_ACTION = "http://tempuri.org/GetHelpDeskCalls";
private static String NAMESPACE = "http://tempuri.org/";
private static String METHOD_NAME = "GetHelpDeskCalls";
static final String URL = "https:/192.2344.123:8080/Service1.asmx";
Button getData;
EditText userID;
TextView data;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.helpdesk);
getData = (Button) findViewById(R.id.button1);
userID = (EditText) findViewById(R.id.txtFar);
data = (TextView) findViewById(R.id.textView1);
Thread nT = new Thread() {
@Override
public void run() {
getData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SoapObject request = new SoapObject(NAMESPACE,
METHOD_NAME);
request.addProperty("userID", userID.getText()
.toString());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
HttpTransportSE androidHttpTransport = new HttpTransportSE(
URL);
try {
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
final String results = androidHttpTransport.responseDump
.toString();
runOnUiThread(new Runnable() {
public void run() {
data.setText(results.toString());
}
});
} catch (Exception e) {
data.setText("Error" + e);
}
}
});
}
};
nT.start();
}
}
做我做一個xml解析的新類然後在Activity中調用它? – user2500733
是的,您可以創建一個新的類來解析數據,並在其構造函數中傳遞參數。 – Andrain
對不起,打擾你我只是盯着android開發,所以我不擅長它可以告訴我如何使用我的代碼上的XML解析器代碼 – user2500733