É o seguinte, estou a receber de um web services um envelope em xml. O problema é que eu quero determinar o que mostrar ao utilizador e isto é que me está a dar dor de cabeça.
Deixo aqui o meu codigo tanto de java como o que recebo do web service.
package com.example.webservice; import android.util.Log; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.PropertyInfo; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransportSE; import java.util.Vector; public class CallSoap { public final String SOAP_ACTION = "http://tempuri.org/executarSQL"; public final String OPERATION_NAME = "executarSQL"; public final String WSDL_TARGET_NAMESPACE= "http://tempuri.org/"; public final String SOAP_ADDRESS = "http://10.0.2.2:6819/webservice1.asmx"; public CallSoap() { } public String call(String St) { String response =null; try { SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME); St = "select count(*) as resultado from curso"; String tipo = "1"; PropertyInfo Stprop =new PropertyInfo(); Stprop.setName("St"); Stprop.setValue(St); Stprop.setType(String.class); request.addProperty(Stprop); PropertyInfo tipoprop =new PropertyInfo(); tipoprop.setName("tipo"); tipoprop.setValue(tipo); tipoprop.setType(int.class); request.addProperty(tipoprop); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS); httpTransport.call(SOAP_ACTION, envelope); response = String.valueOf(envelope.getResponse()); Vector<Object> vector = (Vector<Object>) envelope.getResponse(); Log.d("Response in SOAP", vector.toString()); parseSoapResponse(vector); } catch (Exception e) { e.printStackTrace(); } return response; } public void parseSoapResponse (Vector<Object> vector) { for (int i = 0; i < vector.size(); i++) { SoapObject object = (SoapObject) vector.get(i); if(object != null){ Log.d("resultado",object.getProperty("resultado").toString()); } System.out.print("resultado"+vector); } } }
package com.example.webservice; import android.app.Activity; import android.os.Bundle; import android.app.AlertDialog; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class callfinal extends Activity { public static String rslt =""; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button b1=(Button)findViewById(R.id.button1); final AlertDialog ad=new AlertDialog.Builder(this).create(); b1.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { try { EditText ed2=(EditText)findViewById(R.id.editText2); int b =Integer.parseInt(ed2.getText().toString()); rslt="START"; caller c=new caller(); c.join(); c.start(); while(rslt=="START") { try { Thread.sleep(10); } catch(Exception ex) { } } ad.setTitle("RESULT"); ad.setMessage(rslt); } catch(Exception ex) { } ad.show(); } }); } }
package com.example.webservice; public class caller extends Thread { public CallSoap cs; public String St; public void run(){ try { cs=new CallSoap(); String resp=cs.call(St); callfinal.rslt=resp; } catch(Exception ex) { callfinal.rslt=ex.toString(); } } }
<DataTable xmlns="http://tempuri.org/"> <xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet"> <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="resultado" msdata:Locale=""> <xs:complexType> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element name="resultado" msdata:Locale=""> <xs:complexType> <xs:sequence> <xs:element name="resultado" type="xs:int" minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> </xs:element> </xs:schema> <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"> <DocumentElement xmlns=""> <resultado diffgr:id="resultado1" msdata:rowOrder="0"> <resultado>23</resultado> </resultado> </DocumentElement> </diffgr:diffgram> </DataTable>
Peço desculpa, por tanto codigo, mas é para melhor compreensão de toda a gente. O que eu desejo é que apareça apenas " resultado=23".
Abraço