hi m using a web service. i m doing for a POC. here is my activity class: i m using ksoap2.
package ab.tina;
import java.io.InputStream;
import java.net.URI;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class TinaWebActivity extends Activity {
private TextView txtview;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtview=(TextView)findViewById(R.id.textView1);
try {
SoapObject Request = new SoapObject("http://www.webserviceX.NET/", "GetQuote");
Request.addProperty("symbol", "MFST");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(Request);
HttpTransportSE androidHttpTransport = new HttpTransportSE("http://www.webservicex.net/stockquote.asmx");
Log.e("tag1","err1");
androidHttpTransport.call("http://www.webserviceX.NET/GetQuote", envelope);
Log.e("tag2","err2");
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
Log.e("tag3","err3");
//String str=(String)response.getProperty(1);
txtview.setText(response.toString());
//txtview.setText(response.toString());
Log.e("tag4","err4");
}
catch (Exception e) {
Log.e("tag5","err5");
txtview.setText(e.getMessage());
}
}
}
i m getting result like this:
<string xmlns="http://www.webserviceX.NET/">
<StockQuotes><Stock><Symbol>MFST</Symbol><Last>0.00</Last><Date>N/A</Date><Time>N/A</Time><Change>N/A</Change><Open>N/A</Open><High>N/A</High><Low>N/A</Lo开发者_如何学JAVAw><Volume>N/A</Volume><MktCap>N/A</MktCap><PreviousClose>N/A</PreviousClose><PercentageChange>N/A</PercentageChange><AnnRange>N/A - N/A</AnnRange><Earns>N/A</Earns><P-E>N/A</P-E><Name>MFST</Name></Stock></StockQuotes>
</string>
please tell me how can i parse it . which class i will require and wht method should i use?
well if you want to get info from that you need to search inside of soapobject each node is a soapobject.
in your case you do something like:
resultData = (SoapObject)resultData.resultData.getProperty("StockQuotes");
//now resultData have all node of stockQuotes
resultData = (SoapObject)resultData.resultData.getProperty("Stock");
//now resultdata have stock
//now to parse string saftelly go to ksoap 2 android project download last version
String symbol = resulresultData.getPropertySafelyAsString("Symbol", "NO DATA");
//or
String symbol = resulresultData.getPropertySafelyAsString("Symbol");
//and so on for other XML
have fun happy coding
精彩评论