0

我已经使用 Ksoap2 连接到了 asp.net 服务,它连接良好,但有一件事是我以 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://198.125.364:8080/AndroidServices/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;

                    envelope.setOutputSoapObject(request);

                    try {
                        HttpTransportSE androidHttpTransport = new HttpTransportSE(
                                URL);

                        // androidHttpTransport.call(SOAP_ACTION, envelope);
                        androidHttpTransport.debug = true;
                        androidHttpTransport.call(SOAP_ACTION, envelope);
                        final String ss = androidHttpTransport.responseDump;

                        // final SoapObject response = (SoapObject) envelope
                        // .getResponse();

                        runOnUiThread(new Runnable() {
                            public void run() {


                                data.setText(ss.toString());
                            }

                        });

                    } catch (Exception e) {

                        data.setText("Error");
                    }
                }

            });

        }

    };
    nT.start();
}

}

4

1 回答 1

1

有一个名为 google 的简洁网站,它确实很神奇。

由于您似乎很懒惰,因此您可以使用 3 种基本的 xml 解析方法

SAX parser, DOM parser, XML pull parser

在此处阅读有关 xml 解析的信息

于 2013-07-15T16:20:26.963 回答